golang中的variable和data types

https://golangbyexample.com/variables-in-golang-complete-guide/#What_is_variable

问题

go里面的string为什么是不可变类型的
go里面 1 && 1 语法为什么错误了?

variables

declare variables

var var_name var_type 没有初始赋值的会使用the default value of that type which is also known as zero value of that type

var <variable_name> <type> = <value>

:= operator

data types

import (
“fmt”
“reflect”
“unsafe”
)
获取大小和类型:unsafe.SizeOf 和 reflect.TypeOf
不过从这两个方法的命名上我吐血了,还是太年轻了啊在这里插入图片描述

一、basic types

整数

有符号整型
int
int8
int16
int32
int64
无符号整型
uint
uint8
uint16
uint32
uint64

floats

float32
float64
float64 is the default float type. When you initialize a variable with a decimal value and don’t specify the float type, the default type inferred will be float64.

Complex Numbers

complex64
complex128

Byte

byte是int8的别名
go里面没有char
var b byte = ‘a’

rune

int32

string

string is a read only slice of bytes in golang.
String can be initialized in two ways
s1 := “this is a string”
s2 := `this is a string`

在这里插入图片描述

Booleans

var b bool = true
var b2 bool = false

二、composite types(复合类型)

Arrays


参考图表
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值