It was not difficult to learn the go language last week. It may take time to directly transition from one language to another. I have been typing the code for a day and a half in DOS. It is really annoying and monotonous. I didn't remind you that if you want to read a line of errors, maybe you are used to using visualization tools, working in the black window is always quite uncomfortable. In the help documents provided by the boss, I finally found liteide, a visual tool. according to the information you have found, it is nice to configure it and then use it to write a program. There are also smart prompts, as if writing a program is much happier.
Http://download.csdn.net/detail/lxy15329/4735111 this document I accidentally found, let me find the fun of programming again.
Let's get down to the truth and talk about what we get today.
Today I read the ebook from the beginning. Of course I did not read it at the end. It is difficult for me to do only one thing a day, because I am afraid of being boring, I don't want to do it anymore. E-paper books have read more than half of them, and the rest is the essence of go. The basics are almost the same. Most of the language routines are like this. You just need to be familiar with some differences and have mastered the basics.
The first is about strings.
Write multi-line strings. Eg:
str := "hello" + "world"
This is a problem, because go will resolve it:
STR: = "hello ";
+ "World ";
This is obviously incorrect. If you don't want to talk about it, go will automatically add points. In the end, it is done according to a set of programs. People can only follow this set of programs, rather than command the program according to their own ideas. There are two solutions:
STR: = "hello" +
"World"
Or use reverse quotation marks'
STR: = 'Hello
World'
However, this will include linefeeds and various spaces.
Formatting output: today it's really big, because I wrote a morning program and wondered why % C in go is directly displayed, rather than displaying characters. Because it is developed in liteide, many of them are prompted, so I did not pay attention to it, always using printf or println. It was not until the afternoon that I read the document that I realized that the previous execution was in DOS, so I used printf to format the output. Today, after I input FMT, I press Enter, I only know the output, but I do not care about which function is called. Think about it. Fortunately, I haven't been thinking about this problem all the time. Otherwise, I wish I could beat myself.
I still have some questions about the use of map, because one of the statements is not successfully executed, and this will continue to be solved later.
Example above:
Week: = map [String] int {
"Monday": 1, "Tuesday": 2, "Wednesday", 3,
}
Note that the last comma is required and cannot be missing.
Maybe you only want the value of this map type, instead of the key. You can do this:
For _, days: = range week {
// Do something
}
_ Discard the value after it is obtained, which is exactly used.
To add items to map, week ["Thursday"] = 4
To modify the value, you only need to assign a value to week ["Thursday"] = 0.
To determine whether an element exists
V, OK: = week ["Thursday"]. If yes, the value of OK is true; otherwise, the value of false.
You can also delete elements in map. Delete (Week, "Thursday") is enough.
About functions and custom types. This is actually not difficult, but you need to pay more attention to it in some places. The added package contains functions. If the function name starts with an uppercase letter, it can be exported and called in other packages. If it is a lowercase letter, it can only be called internally. This is always quite uncomfortable. Why is it so troublesome? I often forget it when I write it. How can I remember what the situation is. After a long time in the morning, I suddenly realized it. Similarly, the custom type is also related to case sensitivity.
Type student struct {
Name string
Age int
}
You can use either of the following methods:
I. STU: = new (student)
Stu. Name = "lxy"
Stu. Age = 11
II. STU: = new student {"lxy", 13} // Note: It's a braces. I used parentheses all the time. It's so bitter.
It is worth mentioning that there can be more than one return value for the function in go. This is a commendable place and the writing method is very simple. I will not give an example.
Continue to learn more about the Go language tomorrow, such as concurrency.