Go 语言基本类型总结

Go 基本类型

(1) bool   取值 false, true

(2) string  单行 "str"  `str`

(3) 整型:
       int    int8      int16      int32      int64
     uint    uint8    uint16    uint32    uint64    uintptr
      byte   <->  uint8
      rune   <->  int32

(4) 浮点型:float32  float64

(5) 复数:complex64   complex128    e.g.  1+2i

复合类型

(1) struct
    type S struct {
        field   type
    }

(2) interface
    type I interface {
        func(args) type
    }

类型转换

GO语言是强类型语言,使用变量之前需要声明其类型,类型转换也要求显示声明。隐式类型转换只存在于其他类型转某接口,一般是接口作为函数参数类型,接收实现了该接口的对象。

类型断言

接口转其他类型必须用类型断言
a.(type)
e.g.
type I interface {
     Hello()
}
type S struct {
     Name string
}
func (s S)Hello() {
     fmt.Println(s.Name)
}
var a I=S{"lb"}
v, err := a.(S)
则err为true, v为S类型的变量,值与a相同
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值