In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces how the variable value of the detailed rules of Python variable name is introduced, the content is very detailed, interested friends can refer to it, hope to be helpful to you.
Python needs to use identifiers to name variables. In fact, identifiers are symbols used to name variables, classes, and methods in a program (simply put, identifiers are legal names.
Identifiers need to start with a letter or an underscore _ and can be used with letters, numbers, and underscores. Letters are not limited to 26 English letters, which can include Chinese characters, Japanese characters, etc.
Because Python 3 also supports the UTF-8 character set, identifiers for Python 3 can use characters in multiple languages that UTF-8 can represent. The Python language is case sensitive, so abc and Abc are two different identifiers.
Python 2.x has poor support for Chinese. If you want to use Chinese characters or variables in Python 2.x programs, you need to add # coding:utf-8 "to the first line of the Python source program. Of course, don't forget to save the source file as the UTF-8 character set.
The rules for using identifiers are as follows:
1. Identifiers can be composed of letters, numbers, and underscores (_), in which numbers cannot be used as the beginning.
2. Identifiers cannot be Python keywords, but they can contain keywords.
3. Identifiers cannot contain spaces.
Such as:
# identifiers cannot start with numbers 1AB _ = 10 # can't ab1_ = 10 # can ab_1 = 10 # can # identifiers can't appear with "#" number abc = 10 # can # abc = 10 # can't a#bc = 10 # can't abc# = 10 # can't # can have the following: abc = 10abc1 = 10abc= 10abc_1 = 10 _ = 10_abc = 10_1abc = 10
Python also contains some keywords and built-in functions, which are generally not recommended as variable names.
Keyword cannot be used as a variable name, otherwise an error will be reported
The built-in function can be used as a variable name, but it is not recommended. Although it will not report an error, the built-in function you use will be overwritten by this variable name, so the built-in function cannot be used.
How to check the keywords?
Use python to view:
# Import keyword module import keyword# shows all keywords print (keyword.kwlist)''['False',' None', 'True',' and', 'as',' assert', 'async',' await', 'break',' class', 'continue',' def', 'del',' elif', 'else',' except', 'finally',' for', 'from',' global', 'if' 'import', 'in',' is', 'lambda',' nonlocal', 'not',' or', 'pass',' raise', 'return',' try', 'while',' with', 'yield']'
None of these keywords can be used as variable names:
The following are built-in functions:
On the Python variable name detailed rules of how the variable value introduction is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.