The basic grammar python - Part Ⅱ

Python reserved characters

The following list shows the reserved words in Python. These words can not be used to retain a constant or variable, or any other identifier names.

All Python keywords contain only lowercase letters.

 

Line breaks and indentation



Learning Python and the biggest difference is in other languages, Python http://www.xuanhe.net/ code blocks without using braces  {} class controlled, functions, and other logic judgment. python most unique is to use indentation to write modules.

The number of spaces to indent is variable, but all of the code block statement must contain the same number of spaces to indent, this must be strictly enforced. As follows:

 

The following code will execute error:

 

The implementation of the above code, will appear the following error reminder:

 

 

IndentationError: unindent does not match any outer indentation level error indicates inconsistent indentation you use, some tab key to indent, plenty of spaces to indent, you can change to be consistent.

If  IndentationError: unexpected indent  error, the python compiler is telling you, " Hi, buddy, your file format wrong, may be aligned tab and space no problem", the format of all the python was very strict.

Thus, the number of rows must use the same number of spaces in the first indent Python code block.

We suggest you use for each indentation level  of a single tab  or  two spaces  or  four spaces  , remember not to mix


Multi-line statement

Python statements generally a newline terminator statement.

But we can use the slash (\) line will be divided into multiple lines of statements, as follows:

Statement includes [], {}, or () parenthesis not need to use multi-line connector. Following examples:

Python 引号

Python 可以使用引号( ' )、双引号( " )、三引号( ''' 或 """ ) 来表示字符串,引号的开始与结束必须的相同类型的。

其中三引号可以由多行组成,编写多行文本的快捷语法,常用于文档字符串,在文件的特定地点,被当做注释。

 

Guess you like

Origin www.cnblogs.com/danjiu/p/11304365.html