3_go basis of the data types go study notes

fmt placeholder

  • % T type View
  • View value value value% v Universal Display
  • % # V See descriptor string value by adding ""
  • % B Binary show
  • % D Decimal display
  • % O octal
  • % X hexadecimal
  • % S string
  • % F float
  • % C character

Integer data

int8 int16 int32 int64 uint8 uint16 uint32 uint64

  • uint 32-bit system is uint32 64-bit system uint64
  • int 32-bit system is int64 int32 64 bit systems
  • uintptr unsigned integer used to store a pointer

Hexadecimal

  • Unable to set binary value printed out directly with% b
  • Daily decimal value represents the decimal input print% d
  • Octal value of 0 indicates the beginning of octal data% o print out
  • 0x hexadecimal data printed out at the beginning of the data% x
  • Check the data type% T
  • Setting specified type var = int8 (20) disposed type int8

Digital literal syntax

Go1.13版本之后引入了数字字面量语法,这样便于开发者以二进制、八进制或十六进制浮点数的格式定义数字,例如:

v := 0b00101101, 代表二进制的 101101,相当于十进制的 45。 v := 0o377,代表八进制的 377,相当于十
进制的 255。  而且还允许我们用 _ 来分隔数字,比如说:v := 123_456 等于 123456`0x十六进制整数部分.十六进制小数部分p指数` 看上去和科学计数法很像,事实上也就是把e换成了p,指数计算
从10变为了2。另外因为是每161,所以"0x0.1p0"看上去像0.1,然而它表示的是1/16,0.0625
v1 := 0b00101101
v2 := 0o777
v3 := 89
v4 := 0xFF
v5 := 0x0.1p-2
v6 := 0x0.1p2
fmt.Println(v1, v2, v3, v4, v5, v6)
//结果 45 511 89 255 0.015625 0.25

Float

float32 and two types float64

  • The default value of the bit floating-point type float64
  • float32 type can not be assigned directly to the type float64

Boolean value

  • Boolean default position flase
  • go language is not allowed to cast integer bit Boolean
  • Boolean operations can not participate in value can not be converted to other types

String

String language content go inside utf8 encoded string using the values of the bits of ""双引号content, you can add non-ascii characters directly in the source code languages go, as Chinese is: = "Chinese"

  • Go language strings are wrapped in double quotes! ! !
  • Go language is wrapped in a single quote character! ! !
  • Multi-line strings with the backtick ecs under the following circumstances English which symbol "` "
  • Instead of using the escape path or the like by reverse printing quotes
// 字符串
s := "Hello 沙河"
// 单独的字母、汉字、符号表示一个字符
c1 := 'h'
c2 := '1'
c3 := '沙'
// 字节: 1字节=8Bit(8个二进制位)
// 1个字符‘A’=1个字节
// 1个utf8编码的汉字'沙'= 一般占3个字节

Common string operation
Common Operations

Published 32 original articles · won praise 6 · views 8735

Guess you like

Origin blog.csdn.net/linxue110/article/details/103963440