In programming languages, identifiers are words that the programmer himself prescribes, such as: Class name, function name, property name, variable name, and so on.
- The first character must be either a character in the alphabet or an underscore "_"
- Other parts of the identifier can consist of letters, numbers, and glide lines
- Identifiers are case-sensitive
- Non-ASCII identifiers are also allowed in Python3
Identifiers that begin with an underscore have a special meaning. A class attribute that begins with a single underscore (_foo) cannot be accessed directly, is accessed through the interface provided by the class, cannot be imported with a "from * * * * * * * *", and a double underscore (__foo) represents a private member of a class; A double underscore that starts and ends (__foo__ ) Represents a special method-specific identifier in Python, such as __int__ (), which represents the constructor of a class.
Python reserved word
Reserved words are keywords, and reserved words cannot be used as any identifier names. Python's standard library provides a keyword module that can output all the keywords for the current version:
>>>Importkeyword>>>keyword.kwlist['False','None','True',' and',' as','assert',' Break','class','Continue','def','del','elif','Else','except','finally',' for',' from','Global','if','Import','inch',' is','Lambda','nonlocal',' not','or','Pass','Raise','return','Try',' while',' with','yield']
Comments
In Python, you do not need braces "{}" to represent blocks of code by using indentation, and the number of spaces you indent is variable, but the number of indentation spaces for the same code block statement must be the same.
if True: Print ("True") Else : Print ("False")
If indentation is inconsistent, it can result in a run error
#!/usr/bin/python3#-*-coding:utf-8-*-#file name: test.pyifTrue:Print("Answer") Print("True")Else: Print("Answer") #no strict indentation, maintained at execution time Print("False")
" /****/**** ", line print ("False") ^ indentationerror:unexpected Indent
Single Statement multiple lines
Python usually writes a single statement on one line, but if the statement is long, you can use the backslash "\" to implement a multiline statement, for example:
" a " "b" "c" = A + + C
In "[]", "{}", "()" Do not need to use the backslash "\", for example:
A = {"a""b", "C" "" "keeplive" "" "" "homework"
Data type