Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Go 变量命名规则


Go 变量命名规则

变量可以有短名称(如 x 和 y)或更具描述性的名称(如 age、price、carname 等)。

Go 变量命名规则

  • 变量名必须以字母或下划线字符 (_) 开头
  • 变量名不能以数字开头
  • 变量名只能包含字母数字字符和下划线 (a-z, A-Z, 0-9, 和 _ )
  • 变量名区分大小写(age、Age 和 AGE 是三个不同的变量)
  • 变量名长度没有限制
  • 变量名不能包含空格
  • 变量名不能是任何 Go 关键字

多单词变量名

包含多个单词的变量名可能难以阅读。

您可以使用多种技术使它们更易于阅读

驼峰命名法

除了第一个单词外,每个单词都以大写字母开头

myVariableName = "John"

帕斯卡命名法

每个单词都以大写字母开头

MyVariableName = "John"

蛇形命名法

每个单词之间用下划线字符分隔

my_variable_name = "John"

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.