Numbers
1 | 8 / 5 # division always returns a floating point number |
Strings
1 | 'spam eggs' # single quotes |
List
1 | squares = [1, 4, 9, 16, 25] |
More Control Flow Tools
1 | # if Statements |
Data Structures
1 | # More on Lists |
Modules
1 | # create a file called fibo.py in the current directory with the following contents: |
Input and Output
1 | # Fancier Output Formatting |
Errors and Exceptions
1 | # Syntax Errors |
Classes
1 | # Python classes provide all the standard features of Object Oriented Programming: the class inheritance |
Brief Tour of the Standard Library
1 | # Operating System Interface |
Brief Tour of the Standard Library — Part II
1 | #Output Formatting |
scope of variable
Python 中只有模块(module)、类(class)以及函数(def、lambda)才会引入新的作用域,其它的代码块(如 if/elif/else/、try/except、for/while等)是不会引入新的作用域的,也就是说这这些语句内定义的变量,外部也可以访问,如下代码:
1 | if True: |