本文摘自网络,作者,侵删。
布尔型
一个布尔类型的值只有两种:true和false
字符
golang中没有专门的字符类型,一般使用byte或rune来保存单个字符
其中byte是int8的别名,rune是int32的别名
// byte is an alias for uint8 and is equivalent to uint8 in all ways. It is
// used, by convention, to distinguish byte values from 8-bit unsigned
// integer values.
type byte = uint8
// rune is an alias for int32 and is equivalent to int32 in all ways. It is
// used, by convention, to distinguish character values from integer values.
type rune = int32
byte一般用来保存ascii码以内的,rune用来保存unicode码,涉及到中文的全部使用rune来表示,因为一个中文字符可能是由多个字节组成的,byte表示不了
func TestChar(t *testing.T) {
var c rune = '中'
fmt.Println(c) // 20013
fmt.Printf("%c\n", c) // 中
}
本文来自:简书
感谢作者:大白能_3db0
查看原文:golang基础数据类型-布尔和字符
相关阅读 >>
[Go]解决Go-smtp发送内容乱码和发送html邮件不解析
更多相关阅读请进入《Go》频道 >>

Go语言101
一个与时俱进的Go编程知识库。