basic knowledge A Python identifier
In Python, identifiers are made up 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, which is not directly accessible by the _foo, must be accessed through the interface provided by the class and cannot be imported with the FROM XXX import *;
A __foo that begins with a double underscore represents a private member of a class; A __foo__ that begins and ends with a double underscore represents a special method-specific identifier for Python, such as __init__ (), which represents the constructor of a class.
Python can display multiple statements on the same line, by using semicolons ;
two 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 |
Not |
Assert |
Finally |
Or |
Break |
For |
Pass |
Class |
From |
Print |
Continue |
Global |
Raise |
Def |
If |
Return |
Del |
Import |
Try |
Elif |
Inch |
While |
Else |
Is |
With |
Except |
Lambda |
Yield |
three basic syntax
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.
Code
Code
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
Print ("aaaaaa" +\
"BBBBB" +\
"CCCCCC")
Python Quotes
Python can use quotation marks ( ' ), double quotation marks ( " ), three quotation marks (" ' or "") to denote a string, and the beginning and end of the quotation mark must be of the same type.
Where three quotation marks can be composed of more than one line, writing a shortcut syntax for multiple lines of text, often used in a document string, at a specific location of the file, as a comment
Print (' content using a single single quote ')
Print ("content using single double quotes")
Print (' ' ' content uses three single quotes
Support multi-line output "")
Print ("" "Content uses three double quotation marks
Support multi-line output "" ")
Python comments
A single-line comment in Python starts with #.
# Note
Python Multi-line comments
A multiline comment in Python takes (three single quotes) "Comment content" "or (three double quotation marks)" "" Comment content "".
This is a multiline comment, using single quotation marks. This is a multiline comment, using single quotation marks. This is a multiline comment, using single quotation marks. ‘‘‘
"" This is a multiline comment, using double quotation marks. This is a multiline comment, using double quotation marks. This is a multiline comment, using double quotation marks. """
Output input
Age =int (input (\ "Please enter ages: \"))
Each program (console output)
>>> Print (' Hello Python ')
Python Learning (ii) Basic understanding