package main
import("fmt"
)
func main(){var x intx=100var y  int =100z:=100.11// z:=102.12 //error :=只能用于新变量,自动推断变量类型z=102.11var z2 float32 =99.99z2=100var z3 int =12//z3=13.55   //error:整数不能转变成浮点数,强类型语言fmt.Println("x:",x,"y:",y,"z:",z,"z2:",z2,"z3:",z3)
}

x: 100 y: 100 z: 102.11 z2: 100 z3: 12

go语言数据类型
复数
type ComplexType
ComplexType is here for the purposes of documentation only. It is a stand-in for either complex type: complex64 or complex128.
浮点数

type FloatType
FloatType is here for the purposes of documentation only. It is a stand-in for either float type: float32 or float64.

整数
type IntegerType
IntegerType is here for the purposes of documentation only. It is a stand-in for any integer type: int, uint, int8 etc.

Type类型,任何go类型,但对于任何给定的函数调用,都代表相同的类型
type Type
Type is here for the purposes of documentation only. It is a stand-in for any Go type, but represents the same type for any given function invocation.

布尔
type bool
bool is the set of boolean values, true and false.

字节
type byte
byte is an alias for uint8 and is equivalent to uint8 in all ways. It is used, by convention, to distinguish byte values from 8-bit unsigned integer values.

type complex128
complex128 is the set of all complex numbers with float64 real and imaginary parts.

type complex64
complex64 is the set of all complex numbers with float32 real and imaginary parts.

错误
type error
The error built-in interface type is the conventional interface for representing an error condition, with the nil value representing no error.

type error interface {
Error() string
}

type float32
float32 is the set of all IEEE-754 32-bit floating-point numbers.

type float64
float64 is the set of all IEEE-754 64-bit floating-point numbers.

type 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.

type int16
int16 is the set of all signed 16-bit integers. Range: -32768 through 32767.

type int32
int32 is the set of all signed 32-bit integers. Range: -2147483648 through 2147483647.

type int64
int64 is the set of all signed 64-bit integers. Range: -9223372036854775808 through 9223372036854775807.

type int8
int8 is the set of all signed 8-bit integers. Range: -128 through 127.

rune是int32的别名,在所有方面都等同于int32。按照惯例,它用于区分字符值和整数值。
type rune
rune is an alias for int32 and is equivalent to int32 in all ways. It is used, by convention, to distinguish character values from integer values.

字符串
type string
string is the set of all strings of 8-bit bytes, conventionally but not necessarily representing UTF-8-encoded text. A string may be empty, but not nil. Values of string type are immutable.

无符号整数
type 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.

type uint16
uint16 is the set of all unsigned 16-bit integers. Range: 0 through 65535.

type uint32
uint32 is the set of all unsigned 32-bit integers. Range: 0 through 4294967295.

type uint64
uint64 is the set of all unsigned 64-bit integers. Range: 0 through 18446744073709551615.

type uint8
uint8 is the set of all unsigned 8-bit integers. Range: 0 through 255.

uintptr是一个整数类型,其大小足以容纳任何指针的位模式。
type uintptr
uintptr is an integer type that is large enough to hold the bit pattern of any pointer.

package main
import("fmt"
)
func main(){x,y:=100,50var x1 int var x2 intx1,x2=100,11  fmt.Println("x1:",x1,"x2:",x2,"x:",x,"y:",y)
}
package main
import("fmt"
)
func main(){var (x1 boolx2 intx3 float32)x1=truex2=12x3=12.05fmt.Println(x1,x2,x3)}

true 12 12.05

package main
import("fmt"
)
func main(){   var y1,y2,y3 inty1=1y2=2y3=3fmt.Println(y1,y2,y3)}
package main
import("fmt"
)
func main(){   var a1,a2,a3 inta1,a2,a3=11,22,33fmt.Println(a1,a2,a3)}

go语言基础到提高(3)-变量相关推荐

  1. Swift语言指南(一)--语言基础之常量和变量

    原文:Swift语言指南(一)--语言基础之常量和变量 Swift 是开发 iOS 及 OS X 应用的一门新编程语言,然而,它的开发体验与 C 或 Objective-C 有很多相似之处. Swif ...

  2. go语言基础到提高(12)-函数类型与函数变量

    ```go```go```go package mainimport ("fmt" )type UpdateList func(lst []int) (done bool)//函数 ...

  3. c语言基本数据类型常量,C语言基础学习基本数据类型-变量和常量

    变量和常量 什么是变量和常量?有些数据在程序运行前就预先设定,并在运行过程中不发生变化,称之为常量:有些数据在程序运行中可能发生变化或被赋值,称之为变量. 使用变量前必须先声明一个变量.变量定义的语法 ...

  4. Go语言基础进阶—程序结构—变量

    基于Go语言圣经总结,适合有一定基础的同学,对于提升Go语言的掌握有很大的帮助 建议放大观看

  5. C语言基础——运算符(定义变量、转义字符、输入输出语句、运算符、32个关键字)

    文章目录 一.定义变量 1.如何定义? 2.如何调用? 二.转义字符 二.输入输出语句 1.输出语句 2.输入语句 三.运算符 3.1 赋值运算符: 3.2 算数运算符: 3.3条件运算符 3.4 逻 ...

  6. go语言基础到提高(13)-同步

    defer的主要作用就是在当前函数或者方法返回之前调用一些用于收尾的函数,例如关闭文件描述符.关闭数据库连接以及解锁资源. 只需要在被调用的函数前边加上go关键字,就可以轻松的开启并发执行. pack ...

  7. go语言基础到提高(10)- 包及方法

    src\2.go package mainimport ("test" )func main() {test.Info() } src\test\test.go package t ...

  8. go语言基础到提高(9)-go ide

    LiteIDE is a simple, open source, cross-platform Go IDE. 支持的操作系统 Windows x86 (32-bit or 64-bit) Linu ...

  9. go语言基础到提高(7)-数组

    package main import("fmt")func main(){var sz1 [5]intfor i:=1;i<5;i+=1{sz1[i]=i*5}sz2:=[ ...

最新文章

  1. 《C#多线程编程实战(原书第2版)》——第3章 使用线程池 3.1 简介
  2. idea不自动检查语法_idea自动检查失效-目录中类名下的红色波浪线没有自动消除问题...
  3. Python Unicode与中文处理
  4. 【tensorflow】model.fit() fit函数
  5. 超级棒的170+款web前端开发工具汇总,千万要收藏好!
  6. C++基础知识(二)—— 变量和数据类型
  7. mysql 当天创建分区表_mysql8.0 定时创建分区表记录 每天定时创建下一天的分区表...
  8. 深度学习自学(三十九):SRN骨架检测 Side-output Residual Network for Object Symmetry Detection in the Wild
  9. 20个编写现代 CSS 代码的建议
  10. 中文金融领域情感词典构建
  11. airpak模拟案例_《CFD模拟基本概念》Airpak模拟高级班48讲
  12. 程序员-人事面试题、包含缺点、优点、自我介绍、范文
  13. ReactNative Ios打包流程
  14. 向量叉积和点积混合运算_matlab中的向量的数量积和向量积
  15. 视频直播本地测试服务器搭建
  16. 局部替换算法最小生成树
  17. 采用顺序存储实现队列的初始化、入队、出队操作。/验证实验/
  18. 在Python中文件用Feather格式,与 CSV说再见,速度提升 150 倍!
  19. 全文索引elasticsearch
  20. Android9.0 紧急号码配置

热门文章

  1. Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
  2. 如何让FPGA中的SPI与其他模块互动起来
  3. asp.net三层架构应用详解【收录】
  4. TreeView Checkbox选中
  5. HTML marquee标签详解
  6. 4G网络在物联网应用中的重要性
  7. linux 列出内存/cpu使用率前10的进程
  8. 2.异步回调检测线程结束
  9. p标签里面不能嵌套div
  10. delphi webbrowser 经常用法演示样例