-
阶级关系
1. Programs are composed of modules.
2. Modules contain statements.
3. Statements contain expressions.
4. Expressions create and process objects.
-
教学大纲
Statements
大纲纵览
Python 3.X’s statements
- Python 3.X reserved words.
- 一些简单的示范例子,page 372/1594
1 a, b = 'good', 'bad' 2 3 log.write("spam, ham") 4 5 print('Then Killer', joke) 6 7 if "python" in text: 8 print(text) 9 10 for x in mylist: 11 print(x) 12 13 while X > Y: 14 print('hello') 15 16 while True: 17 pass 18 19 while True: 20 if exittest(): break 21 22 while True: 23 if skiptest(): continue 24 25 def f(a, b, c=1, *d): 26 print(a+b+c+d[0]) 27 28 # 其中一个*号代表list或者tuple,**代表map或者dict 29 def f(a, b, c=1, *d): 30 return(a+b+c+d[0]) 31 32 def gen(n): 33 for i in n: 34 yield i*2 35 36 x = 'old' 37 def function(): 38 global x, y: 39 x = 'new' 40 41 # https://stackoverflow.com/questions/1261875/python-nonlocal-statement 42 def outer(): 43 x = 'old' 44 def function(): 45 nonlocal x: 46 x = 'new' 47 48 import sys 49 50 from sys import stdin 51 52 class Subclass(Superclass): 53 staticData = [] 54 def method(self): 55 pass 56 57 try: 58 action() 59 except: 60 print('action error') 61 62 # 需进一步理解 63 raise EndSearch(location) 64 65 assert X > Y, 'X too small' 66 67 with open('data') as myfile: 68 process(myfile) 69 70 del data[k] 71 del data[i:j] 72 del obj.attr 73 del variable