【Go】Go语言基本数据类型

2021-09-16 11:06:47 浏览数 (2)

整型

  • int // int is a signed integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, int32.
  • int8: Range: -128 through 127.
  • int16: Range: -32768 through 32767.
  • int32(rune): Range: -2147483648 through 2147483647.
  • int64: Range: -9223372036854775808 through 9223372036854775807.
  • uint // uint is an unsigned integer type that is at least 32 bits in size. It is a distinct type, however, and not an alias for, say, uint32.
  • uint8(byte): Range: 0 through 255.
  • uint16: Range: 0 through 65535.
  • uint32: Range: 0 through 4294967295.
  • uint64: Range: 0 through 18446744073709551615.

浮点型

  • float32:float32 is the set of all IEEE-754 32-bit floating-point numbers.
  • float64:float64 is the set of all IEEE-754 64-bit floating-point numbers.
代码语言:javascript复制
package main

import "fmt"

func main()  {
	var v1=123
	fmt.Printf("v1的类型是%Tn",v1)

	var v2 int = 123
	fmt.Printf("v2的类型是%Tn",v2)

	var v3 float64 = 123
	fmt.Printf("v2的类型是%Tn",v3)

	var v4 = 123.0
	fmt.Printf("v2的类型是%Tn",v4)

	var v5 = "你好"
	fmt.Printf("v5的类型是%Tn",v5)

	var v6 = '岳'
	fmt.Printf("v6的类型是%Tn",v6)
	fmt.Printf("v6的值是%vn",v6)
	fmt.Printf("v6的字符是%cn",v6)
	fmt.Printf("23731的类型是%cn",23731)

	var v7 = (100==(40 60))
	fmt.Printf("v7的类型是%T,值是%vn",v7,v7)

	var v8 = ('岳'==23731)
	fmt.Printf("v8的类型是%T,值是%vn",v8,v8)
	fmt.Printf("23731的字符形式是%cn",23731)
	fmt.Printf("岳的数字形式是%dn",'岳')
	fmt.Printf("岳在字符集中的序号是%dn",'岳')

}

0 人点赞