I. Basic input and OUTPUT
# !/usr/bin/python Print " Hello, python!. ";
Second, Python identifiers
In Python, identifiers are composed of letters, numbers, and underscores.
In Python, all identifiers can include English, numeric, and underscore (_), but cannot begin with a number.
Identifiers in Python are case-sensitive.
Identifiers that begin with an underscore are of special significance. A class attribute that begins with a single underscore (_foo) cannot be accessed directly, and is accessed through the interface provided by the class and cannot be imported with "from XXX import *";
A double underscore (__foo) represents a private member of a class; a double underscore (__foo__) represents a special method-specific identifier for Python, such as __init__ (), which represents the constructor of a class.
Third, Python reserved characters
The following list shows the reserved words in Python. These reserved words cannot be used as constants or variables, or as any other identifier name.
All Python keywords contain only lowercase letters.
and exec notassert finally or Break for Passclass from PrintContinue Global Raisedef if returndel Import Tryelif inch whileElse is withexcept Lambda yield
Four, line and indent
The biggest difference between learning Python and other languages is that Python's code block does not use curly braces ({}) to control classes, functions, and other logical judgments. Python's most distinctive feature is the use of indentation to write modules.
The amount of whitespace indented is variable, but all code block statements must contain the same amount of indentation whitespace, which must be strictly enforced. As shown below:
if True: Print " True " Else : Print " False "
The following code will execute the error:
if True: Print " Answer " Print " True " Else : Print " Answer " Print " False "
Therefore, you must use the same number of indent spaces in a Python code block.
Five, multi-line statements
A new line is generally used as the Terminator for a statement in a Python statement.
But we can use a slash (\) to divide a line of statements into multiple lines of display, as follows:
Total = Item_one ++ item_three
The statement contains [], {}, or () parentheses do not need to use a multiline connector. The following example:
days = [' Monday ', ' Tuesday ', ' Wednesday ',
' Thursday ', ' Friday ']
Python basic syntax