Cloud computing python automation: Python identifiers Explained

Source: Internet
Author: User

Some symbols and names that developers customize in the program. Identifiers are defined by themselves, such as variable names, function names, and so on. In daily life, the identifier is used to designate something, a person, to use it, his or her name; when solving equations in mathematics, we often use variables or function names such as those used by the user, identifiers are names for variables, constants, functions, and block statements, and we all call them identifiers. Identifiers may be words, numbers, letters, symbols, or they may be made up of the above elements.

Python identifier:

    1. Used to identify the name of a variable, function, class, module, or other object.

    2. An identifier begins with the letters A through Z or a through Z followed by 0 or more letter underscores (_) and Numbers (0?9), and the Python identifier does not allow punctuation marks, such as @, $,%, and so on.

    3. Python is case-sensitive.

Identifier Naming conventions:

? The class name is in uppercase letters and all other identifiers in lowercase letters.

? An identifier that begins with a single, leading underscore indicates that the meaning specified by the identifier is private.

? The identifier that begins with two leading underscores represents a strong private identifier.

? If the end of the identifier also has two underscores at the end, the identifier is a language-defined special name.

Avoid using underscores as the start of variable names:

Because underscores have special meanings for the interpreter and are symbols used by built-in identifiers, it is recommended that programmers avoid using underscores as the starting point for variable names.

In general, variable name ' _xxx ' is considered "private" and cannot be used outside of a module or class.

When a variable is private, it is good practice to use _xxx to represent variables.

Because the variable name XXX has a special meaning for Python, this naming style should be avoided for common variables

Reserved words:

Reserved words cannot be used as constants or variables, or any other identifier. All Python keywords contain only lowercase letters.

Query all the keywords in the current version of Python:

>> Import keyword #如果系统中没有这个模块, need to install Python-docs

>> keyword.kwlist

[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

Determine if it is a keyword:

>> Keyword.iskeyword (' False ')

This will return true

Cloud computing python automation: Python identifiers Explained

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.