当前位置:网站首页>Go language learning notes 1.2- variables
Go language learning notes 1.2- variables
2022-06-26 06:23:00 【Who made the promise】
One 、Go Language variables
- Declare variables separately
package main
import "fmt"
func main(){
// The first one is
var a int // Declare variable type In assignment ; No assignment a Default equal to 0
a=100
fmt.Println("a=",a)// Inside , Be similar to PHP Inside .JAVA Inside +
// The second kind
var num=100 // Automatically declare variable types based on values ( Type derivation )
fmt.Println("num=",num)
// The third kind of
str :="100" // Omit var【 Cannot be a declared variable , Otherwise, there will be compilation errors 】
fmt.Println("str=",str )
}
- Declare multiple variables at once
// The first one is Declare multiple variables at once
var num1,num2,num3 int
fmt.Println("num1=",num1,"num2=",num2",num3=",num3)
// The second kind Assignment form
var i1,i2,i3=100,"100",200
fmt.Println("i1=",i1,"i2=",i2",i3=",i3)
// The third kind of Omit var
n1,n2,n3 := 100, 20,'name'
fmt.Println("n1=",n1,"n2=",n2",n3=",n3)
3. Global variables
package main
import "fmt"
var n1 int
var n2 int
var n3 int
func main(){
fmt.Println("n1=",n1,"n2=",n2",n3=",n3)
}
4. Variable use considerations
package main
import "fmt"
func main(){
var i int =10
// Variables cannot change the data type
i=1.2 // An inconsistent data type error will be thrown
// Variables cannot be declared repeatedly
var i string // Will throw variables that have been defined , Cannot be defined repeatedly
}
边栏推荐
- Introduction to the use of TS generics in functions, interfaces and classes
- Understanding of nil in go language
- DS18B20详解
- ByteDance starts the employee's sudden wealth plan and buys back options with a large amount of money. Some people can earn up to 175%
- 01 golang and matlab code of knapsack problem
- Go语言学习笔记 1.1
- Multi thread synchronous downloading of network pictures
- Alarm operation and Maintenance Center | build an efficient and accurate alarm collaborative processing system
- Laravel 实现 groupBy 查询分组数量
- 3.pyinstaller module introduction
猜你喜欢

Evolution history of qunar Bi platform construction

Message queuing - omnidirectional comparison

MySQL-08
How can an enterprise successfully complete cloud migration?

EFK升级到ClickHouse的日志存储实战

TCP连接与断开,状态迁移图详解

实时数仓方案如何选型和构建

数据治理工作的几种推进套路

Redis multithreading and ACL

连接数服务器数据库报:错误号码2003Can‘t connect to MySQL server on ‘服务器地址‘(10061)
随机推荐
Requirement analysis of personal blog system
工作积累——Web请求中使用ThreadLocal遇见的问题
连接数服务器数据库报:错误号码2003Can‘t connect to MySQL server on ‘服务器地址‘(10061)
Pytorch uses multi GPU parallel training and its principle and precautions
TCP连接与断开,状态迁移图详解
Transformer中的Self-Attention以及Multi-Head Self-Attention(MSA)
volatile应用场景
The sysdig 2022 cloud native security and usage report found that more than 75% of the running containers have serious vulnerabilities
Logstash -- send an alert message to the nail using the throttle filter
New generation engineers teach you how to play with alluxio + ml (Part 1)
canal部署、原理和使用介绍
MySQL-06
Failed to configure a DataSource: ‘url‘ attribute is not specified and no embedded datasource could
视图简析
实时数仓方案如何选型和构建
Getting to know concurrency problems
Connexion et déconnexion TCP, détails du diagramme de migration de l'état
Deeply uncover Ali (ant financial) technical interview process with preliminary preparation and learning direction
China micro cultivator market trend report, technical dynamic innovation and market forecast
zip(*arg)的用法