1. in Canvas, the origin is always on upper-left corner.
2. On a 300 by 200 pixel canvas, the pixel coordinates range from 0, 0 in the top left to 299, 199 in the bottom right.
3.draw handler needs to be registered.
4. use Brackets [], to define the position of the texts. The position is the lower-left corner of the string.
5. print s1[0] 是从0开始数一个string, 第一个字母是第0个。
6. print s1[-1] 是print 最后一个字母。
7. print s1[0:7] 是print 前7个字母,不包括7所代表的的那个字母,是开区间。
8. s2[:13] 前13位。
9. str(123)把 数字变成string; int()就是string转成整数
10. position = [50, 60] position[0] = 50 position[1] = 60
11. decomposition the program is important. draw is draw, timer is timer, message is message. One has nothing to do with another.
12. don't forget start the frame. frame.start() . same for timer. timer1.start() timer2.start()
WEEK 4
1. list [] empty list; [1,2,3] or ['hello', 'goodbye']; position = [4, 9]; even other list inside list.
[[1,3], ['a', 'b'], []]
2. len() return the length of the list.
3. access the list print l[0] index start from 0 . l2[1:3] 是l2里的第二项和第三项,不包裹第四项。
4. l2[0] = 'cheese'
5. chr() turns the key codes number into caracter.
6. in Python power use ** 2 it is square
7. In python, for update vector, we need update x and y separately.
8. a is a list, and b = a, if change a element in a, b is changed too.
9. a is a list, b = list(a) , b is the same list as a , but when updating a , b unchanged.
10. In a function , we do not need "global" if using mutation. We only need it when doing assignment.
11. type([1,2,3]) is list, type((1,2,3)) is tuple. tuple is not mutable. If you want to protect your data, you'd better save it as a tuple.
没有评论:
发表评论