Python – Variable Names

Variable Names

  • MUST start with a letter or the underscore character
  • CANNOT start with a number
  • can only contain alpha-numeric characters and underscores (A-z, 0-9, and_ )
  • case-sensitive (age, Age and AGE are three different variables)
  • CANNOT be any of the Python Keywords

Legal variable names:
myvar = “John”
my_var = “John”
_my_var = “John”
myVar = “John”
MYVAR = “John”
myvar2 = “John”

Illegal variable names:
2myvar = “John”
my-var = “John”
my var = “John”

Camel Case – each word, except the first, starts with a capital letter:
myVariableName = “John”

Pascal Case – each word starts with a capital letter:
MyVariableName = “John”

Snake Case – each word is separated by an underscore character:
my_variable_name = “John”

原文链接:Python – Variable Names

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享
Many people start a career with a dream, then get busy forgetting it.
很多人一开始为了梦想而忙,后来忙得忘了梦想
评论 抢沙发

请登录后发表评论

    暂无评论内容