当前位置:网站首页>Go learn 02 basic knowledge
Go learn 02 basic knowledge
2022-07-28 02:11:00 【Little girl】
1.golang Classification of annotations in
- Line notes , Shortcut key Ctrl+/ , Uncomment the same
- Block annotation , Shortcut key Alt+Shift+A, Uncomment the same
All programming language annotations are similar
2. Variable definitions , Use it directly var receive ,go Infer the variable type by yourself .

image C# Some programming languages , When you define a variable, you need to specify the variable type , for example string msg="hello go", Now you can use it directly var To replace ,var Is what your value type is , What type it returns .
2.1 Variable range
- Package level variables , It's a global variable , It can be used in all methods of the current program .
- Function level variables , It's a local variable , Can only be used within the current method .
Be careful : stay Go in , The same variable name is allowed , But in other languages , for example C# The same variable name is not allowed . And in Go in , There is a variable name with the same name , Function level variable names have the highest priority .
2.2 Variable declaration method
- var Mode of declaration , Automatically infer variable types from values , There is an introduction above
- Short notice , Use the mask : Statement No , It also automatically infers variable types
Be careful :1. The variable name of a short declaration must be unique , The same short declaration variable cannot and will not exist , Because it will directly prompt the error , for example :
2. The short declaration must be defined in the function body to use , Cannot be at package level ( overall situation ) Define the use of .
2.3 Merging of variables
Why should variables be merged , Is to reduce the amount of code and beautiful , It can also achieve the same effect as defining multiple variables .
example 1: When we need to define multiple short declaration variables , It is usually defined as .
But it can be defined in this way :
example 2: Normal multiple variables are generally defined in this way
But in fact , It can be like this ,
![]()
Even importing multiple packages can be written in this form
Be careful : Variables defined in the function body , You have to use . If it is not used, it will prompt an error
2.4 Variable naming conventions
- It can't be go Key words of
- Cannot start with a number
- Variable names can only consist of strings , Numbers , Underline composition
- Variable declaration uses hump specification , Or several English combinations , for example :hello_world or helloWorld
- Variable names are case sensitive , for example :Hello and hello It's two different variable names
See the official website for details Go Language course | Novice tutorial (runoob.com)
边栏推荐
- Hcip day 12 notes
- N32l43x FLASH read \ write \ erase operation summary
- 自定义类型:结构体,枚举,联合
- Gbase 8C recovery control function
- Traversal and properties of binary trees
- They are all talking about Devops. Do you really understand it?
- 对话Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
- synchronized详解
- Typescript中类的使用
- Use of recursion: 1. Convert the tiled array to a tree 2. Convert the tree to a tiled array
猜你喜欢

Redis设计规范

Structure pseudo class selector - find single - find multiple - nth of type and pseudo elements

Fluorite network, difficult to be a "lone brave"

Flume(5个demo轻松入门)

uniapp 总结篇 (小程序)

54:第五章:开发admin管理服务:7:人脸入库流程;人脸登录流程;浏览器开启视频调试模式(以便能够在本机的不安全域名的情况下,也能去开启摄像头);

synchronized详解

JS what situations can't use json Parse, json.stringify deep copy and a better deep copy method

LeetCode高频题128. 最长连续序列,经常被互联网大厂面试考到

##ELK日志分析系统搭建##
随机推荐
The petrochemical industry is facing the tide of rising prices, and the digital dealer distribution system platform enables dealers and stores
一种比读写锁更快的锁,还不赶紧认识一下
The principle and implementation of loss function cross entropy
都在说DevOps,你真正了解它吗?
focal loss原理及实现
二叉树的遍历和性质
Domain Driven Design -- Terminology
They are all talking about Devops. Do you really understand it?
Gbase 8C configuration setting function
Flume(5个demo轻松入门)
Gbase 8C database object size function (I)
Sample imbalance - entry 0
Talk to ye Yanxiu, an atlassian certification expert: where should Chinese users go when atlassian products enter the post server era?
day7
shell正则和元字符
Behind every piece of information you collect, you can't live without TA
QGIS制图:矢量数据制图流程及导出
Use of recursion: 1. Convert the tiled array to a tree 2. Convert the tree to a tiled array
Starfish Os X MetaBell战略合作,元宇宙商业生态更进一步
软件测试面试题:请详细介绍一下各种测试类型的含义?











