Go 转义字符、注释的使用:
一、Go 转义字符:
-
制表位( \t ):实现对齐的功能(tab键)
package main import "fmt" func main(){ fmt.Println("hello\tworld!") } // 输出结果: hello world!
-
换行符( \n):
package main import "fmt" func main(){ fmt.Println("hello\nworld!") } // 输出结果: hello world!
-
一个反斜杠(\ \):
package main import "fmt" func main(){ fmt.Println("hello\\world!") } // 输出结果:hello\world!
-
一个指定符号(\ "):
package main import "fmt" func main(){ fmt.Println("hello\"world!") } // 输出结果:hello"world!
-
一个回车(\ r):从当前行的最前面开始输出,覆盖掉以前的内容:
package main import "fmt" func main(){ fmt.Println("老王去买烟酒\r张三") } // 输出结果:张三去买烟酒
二、Go 语言注释:
注释就是,说明解释程序的文字。注释提高了代码的阅读性。
1.行注释:
基本格式: //
package main
import "fmt"
func main(){
fmt.Println("hello world!")
// fmt.Println("hello world!") 已经被注释
// fmt.Println("hello world!") 已经被注释
}
// 输出结果:hello world!
2.块注释:
基本格式:/* 注释内容 */
package main
import "fmt"
func main(){
fmt.Println("hello world!")
/*
fmt.Println("hello world!") 已经被注释
fmt.Println("hello world!") 已经被注释
*/
}
// 输出结果:hello world!
3.注意细节:
- 对于行注释和块注释,被注释的文字,不会被Go编译器执行;
- 块注释里面不允许块注释嵌套;