Week 5
1. in mouse click, there should be a position parameter, which is a tuple, unmodifiable.
2. 可以用 list(pos)
3. lst.index(8), return the position of 8 in the list.
4. 82 in lst returns T, F
5. lst.append(632) adds 632 to the end of the list. one more element added.
6. lst.pop(4) remove the value in position 4; lst.pop() remove the last element, and it is the last element..
7 for ball_pos in ball_list. 这里的in 和上面 4 in lst 里面的不一样,这里的是一个接着一个的跑。
8 for kccc in ball_list, 这里面的kccc没有必要是事先定义好的,只要自己心里面认为,并且之后的代码用法一致就好。
9. never remove anything when you in a iteration loop. if you want to remove something, keep track the things and remove it later.
10. start something simple, make it working. modify it, keep going. keep it working....modify it. just make small change.
11. Dictionary: actually a mapping. Key -> value. d1= {1:45,‘a’: 55} 定义1是45, a 是55. print d1[1] 返回的是45
12 if index in a dictionary, just actuall iterate the keys.
13. if something in Python is a constant and never gonna be changed, use the name all capital.
14. def square(number):
return [n**2 for n in numbers]
15. def balls_in_range2(ball2):
return [ball for ball in balls if is_in_range(ball)] 14, 15 shows neater way for loop
16. length of a list is 5, but index is from 0, so the max index is 4.
17 dictionary has no order. only un-mutable values as key.
18 d[500] = "wow" if there is no key 500, it will add key 500 and value wow automatically.
d[(1,2)] = 10, map (1,2) to 10
19 for key, value in samplelist.items(): 就是成组循环key 和 value
20. samplelist.values() 是仅仅循环value
Week 6
1. Class name should be always capitalized
2. create a field inside an object, use dot, e.g. self.name
3.当object要call 一个class 里面的method时, 就用 objectname.methodname, 但是一定要保证这个object是这个class里面的object。可以用 type(objectname) 来查看。
4.在任何class method 里,第一个参数永远是self,这个会由python自己来管理。
5. class 里面, self 就是object本身。
6. when to create a object in a class, the first function always __init__
7. in each function in a class, self needs to be a prameter
8. While loop while condition:
expression
9. in While loop, we do not know when the loop will end, unlike the for loop.
没有评论:
发表评论