Go language escape characters include: 1. "\t", which represents a tab character, which is usually used for typesetting; 2. "\n", which represents a newline character; 3. "\", which represents A \ symbol; 4. A double quotation mark "; 5. "\r", indicating a carriage return.
The operating environment of this article: Windows7 system, GO 1.18 , Dell G3 computer.
Go language escape character (escape char)
Description: Commonly used escape characters are as follows:
\t: Represents a tab character, which is usually used for typesetting.
\n: Line break character
Because in the Go language, there are only double quotes. If you want to put double quotes in the output content, you have to use conversion Definition characters, unlike in python, you can use single quotes on the outside and double quotes on the inside.
\r: a carriage return fmt.Println("Snow Mountain Flying Fox of Tianlong Babu\r Zhang Fei");It is also overwritten in go, but it can only be The length of the coverage itself, for example, this output is "Zhang Fei Ba Bu Snow Mountain Flying Fox"
CommentsBasic syntax: //Comment content
Add two slashes in front of each line to comment this line.
ctrl / Just It will comment all the multiple lines of code you selected.
2) Block comment
Basic syntax: /*
Comment content
*/
This is equivalent to the """ multi-line comment content in python """Go language standard code style
2. There must be correct indentation and white space (such as calculations A space should be added around the character to make the code clearer)
3. Go language coding style.
Correct coding style
package main import"fmt" funcmain(){ fmt.Println("hello,world!") }
Wrong coding style
package main import"fmt" funcmain() { fmt.Println("hello,world!") }
[Go language does not allow writing like this, it is wrong!]
4. The longest length of a line should not exceed 80 characters. If it exceeds, please use line breaks to display, and try to keep the format as elegant as possible
When we write code that is very irregular but does not make mistakes, we can use gofmt -w file name in cmd to format the code and rewrite it. When the programmer reopens the file, the code has been formatted in a standardized way.
Golang Official Programming GuideOn the first page after entering, click tour-> Select Simplified Chinese to enter the Chinese version of Go Programming Guide
or the package on the first page, Golang official standard library API document , https://golang.org/pkg You can view the functions and usage of all Golang packages.
What is an API? This is also a question that has troubled me for a long time.
Explanation of terms: API
api: applicationprogram interface: application programming interface. These are the functions of each of our Go packages.
Golang Standard Library API Document
The above is the detailed content of What are the escape characters in go language?. For more information, please follow other related articles on the PHP Chinese website!