当前位置:网站首页>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)
边栏推荐
- [database data recovery] data recovery case of insufficient disk space of SQL Server database
- Vxe table/grid cell grouping and merging
- Cloud native enthusiast weekly: the evolution of Prometheus architecture
- Implementation of mongodb/mongotemplate.upsert batch inserting update data
- Traversal and properties of binary trees
- shell正则和元字符
- focal loss原理及实现
- 轻量版项目管理系统
- Gbase 8C transaction ID and snapshot (I)
- 【Star项目】小帽飞机大战(六)
猜你喜欢

Process data and change the name of data

After learning the loop, I came across the problem of writing factorial of N, which caused a series of problems, including some common pitfalls for beginners, and how to simplify the code

Leveraging the blue ocean of household appliances consumption with "digital channels", the dealer online system enables enterprises to further their business

C# 使用Abp仓储访问数据库时报错记录集

MPLS tunnel experiment

Forget the root password

Huawei app UI automation test post interview real questions, real interview experience.

对话Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?

2022软件测试技能 Robotframework + SeleniumLibrary + Jenkins web关键字驱动自动化实战教程

开源飞控(PX4、ardupilot)
随机推荐
Flex布局学习完成PC端
Hcip day 12 notes
轻量版项目管理系统
sftp文件/文件夹上传服务器
Gbase 8C transaction ID and snapshot (V)
Enterprise operation and maintenance practice - using aliyun container image service to pull and build images of overseas GCR and quay warehouses
[database data recovery] data recovery case of insufficient disk space of SQL Server database
结构伪类选择器—查找单个—查找多个—nth-of-type和伪元素
Fluorite network, difficult to be a "lone brave"
你所不知道的WMS
Gbase 8C annotation information function
Huawei app UI automation test post interview real questions, real interview experience.
The principle and implementation of loss function cross entropy
Data output - dynamic drawing
Process data and change the name of data
Talk to ye Yanxiu, an atlassian certification expert: where should Chinese users go when atlassian products enter the post server era?
FreeRTOS kernel summary
Structure pseudo class selector - find single - find multiple - nth of type and pseudo elements
对话Atlassian认证专家叶燕秀:Atlassian产品进入后Server时代,中国用户应当何去何从?
synchronized详解











