Go 语言转义字符、注释的使用

Go 转义字符、注释的使用:

一、Go 转义字符:

  1. 制表位( \t ):实现对齐的功能(tab键)

    package main
    
    import "fmt"
    
    func main(){
    	fmt.Println("hello\tworld!")
    }
    
    // 输出结果:
    hello   world!
    
  2. 换行符( \n)

    package main
    
    import "fmt"
    
    func main(){
    	fmt.Println("hello\nworld!")
    }
    // 输出结果:
    hello
    world!
    
  3. 一个反斜杠(\ \)

    package main
    
    import "fmt"
    
    func main(){
    	fmt.Println("hello\\world!")
    }
    
    // 输出结果:hello\world!
    
  4. 一个指定符号(\ ")

    package main
    
    import "fmt"
    
    func main(){
    	fmt.Println("hello\"world!")
    }
    
    // 输出结果:hello"world!
    
  5. 一个回车(\ 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.注意细节:

  1. 对于行注释和块注释,被注释的文字,不会被Go编译器执行
  2. 块注释里面不允许块注释嵌套
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值