What are the escape characters in go language?

藏色散人
Release: 2023-02-10 15:49:09
Original
8850 people have browsed it

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.

What are the escape characters in go language?

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

  • ##\ : A\

  • ##" : A "
  • 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");
  • This is a bit similar to \r in python. It overwrites the content of the last output every time.

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"

Comments

There are two forms of comments in Golang

1) Line comment

Basic 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 """


Note: There cannot be block comments inside block comments, which means there cannot be nesting

Go language standard code style

1. The official recommendation is to use line comments

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!")
}
Copy after login

Wrong coding style

package main 
import"fmt" 
funcmain() {
    fmt.Println("hello,world!")
}
Copy after login

[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 Guide

Instructions: Golang official website https://golang.org, sometimes cannot be accessed, you have to bypass the wall. Well, I personally have never successfully accessed it.

On 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

    API (Application Programming Interface, application programming interface) is the basic programming interface provided by Golang.
  • The Go language provides a large number of standard libraries, so Google also provides corresponding API documents for these standard libraries to tell developers how to use these standard libraries. , as well as methods included in the standard library.

  • Golang Chinese website online standard library documentation: https://studygolang.com/pkgdoc (accessible, very nice)
  • Recommended learning :
  • Golang tutorial

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!