Learning a development language first of course is to be familiar with its grammar, Python syntax is relatively simple, here from the basics of the beginning to understand.
Identifier
1. The first character must be a letter in the alphabet or an underscore ' _ '.
2. The other parts of the identifier are composed of letters, numbers, and underscores.
3. Identifiers are case sensitive.
Reserved words
Reserved words are keywords and cannot be used to make any identifiers. In Python, with a keyword module, the execution keyword.kwlist can output all the reserved words of the current version, as follows:
[' False ', ' None ', ' True ', ' and ', ' As ', ' Assert ', ' 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 ' ]
Comments
Code comments are essential in the process of writing code, and a single line of comments in Python begins with #, such as:
Print("Hello, www.5bug.wang!" )# Follow my starling learn python
Line and indent
Python's most distinctive feature is the use of indentation to represent blocks of code, which do not require braces ({}), and the number of spaces that are indented is mutable, but statements of the same code block must contain the same number of indentation spaces.
Multi-line statements
Python is usually a line to complete a statement, but if the statement is long, we can use a backslash (\) to implement a multi-line statement.
The practice code is as follows:
Print("Hello, www.5bug.wang!.") # Follow my starling and learn python# variable DeclarationA= 1B= 2C= 3# Multi-Line code exerciseD= A + B + Cif D >10: print ( "D greater than ten" ) else: print ( "D less than or equal to" print ( "code indentation exercise Statement 1" print ( "code indent practice Statement 2"
The output is:
Hello, www.5bug.wang!.
D is less than or equal to 10
Code Indentation Practice Statement 1
Code Indentation Practice Statement 2
————————————————— – Gorgeous Split-line ————————————————— –
...... Cond
Original address: http://www.5bug.wang/share/149.html
My starling Learn Python (iii): Understanding Python basic Syntax (i)