Python 程序员的 Golang 学习指南(III): 入门篇

您所在的位置:网站首页 python程序员指南 Python 程序员的 Golang 学习指南(III): 入门篇

Python 程序员的 Golang 学习指南(III): 入门篇

2024-02-13 16:30| 来源: 网络整理| 查看: 265

基础语法 类型和关键字 类型 // 基础类型 布尔类型: bool 整型: int8,uint8,int16,uint16,int32,uint32,int64,uint64,int,rune,byte,complex128, complex64,其中,byte 是 int8 的别名 浮点类型: float32 、 float64 复数类型: complex64 、 complex128 字符串: string 字符类型: rune(int32的别名) 错误类型: error // 复合类型 指针(pointer) 数组(array) 切片(slice) 字典(map) 通道(chan) 结构体(struct) 接口(interface) 关键字 break default func interface select case defer go map struct chan else goto package switch const fallthrough if range type continue for import return var 变量

Go 同其他语言不同的地方在于变量的类型在变量名的后面,不是 int a,而是 a int。至于为什么这么定义,Go 的官方博客有给出解释,有兴趣的可以参考下。

变量定义语法如下:

var a int a = 2 // 或者 a := 2 // 同时定义多个变量 var ( a int b bool ) // 同时给多个变量赋值 a, b := 2, true 操作符 + & += &= && == != ( ) - | -= |= ||


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3