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.
2013年5月14日星期二
2013年5月6日星期一
Class notes for Introduction Python_week 1 and 2
1. variable name: only start with "_" or letters. Not start with number. 也最好不要用点 . 在中间
2. "=" assign; "==" logical comparison.
3. update variable: my_age +=1. take the current variable value and plus 1 as new variable value.
4." : " 意味着下面要写一个block of codes. 下面的要indent,几个indent没关系,重要的是一致。when the indent is done, the block of codes is done.
5. function does not have a parameter. In this case, no input, function return NONE.
6. -3%800 结果是 797
7. 35//10,是把35除以10,然后取小数点前面剩下的数
8. str(aaa) + str(bbb) +"1111" 是把这三个string 都连起来。
9. if elif else
10 在 function 里面解释, 用三个连续的 双引号“”“在前, 也用三个”“” 在后。叫做documentation。 解释这个方程式做什么的。 用comment也行。
11. x += y + x 意思是 x=x+y 然后再加上x。 和 x=x+y 意思不同。
if condition:
result
elif condition:
result
else:
result
要写 x ==1 or x == 2, 不能 x ==1 or 2
WEEK TWO
1. Events : Input; Keyboard; Mouse; Timer
2. there is a event queue in Python which we cannot see. event一个一个的执行,不能两个一起执行。如果同时出发两个事件(比如点鼠标和按键盘),python会形成一个Queue,一个一个执行。
3. 当event发生的时候,python 会去执行相对应的Handler.
4. all the variables created inside a function are called Local variables, it can only be used in the function.
5.如果在function 里定义一个和外面的variable一样名字的variable。在function里面按你定义的走,但是外面的不影响。
6. 挡在一个function里面要创建或调用一个global variable的话,就写出来 global number1
7. Program Structure: 1. Globals (State); 2. Helper Functions ;3 . Classes(Later)
4. Define event handlers; 5. create a frame; 6. register event handlers. 7. start frame & timers
8. simple gui 里面是里面 string input(text input), 要用 function int() 转换成integer number 或者用float() 来转换成floating point number.
9. 当写一个方程,没有说return什么东西的话。python会return NONE。 因为Python总是要return一个东西。
10. 写方程的时候,在每一步都加上print的输入和输出的东西,会是很好的debug工具。 最好还能加上lable
2. "=" assign; "==" logical comparison.
3. update variable: my_age +=1. take the current variable value and plus 1 as new variable value.
4." : " 意味着下面要写一个block of codes. 下面的要indent,几个indent没关系,重要的是一致。when the indent is done, the block of codes is done.
5. function does not have a parameter. In this case, no input, function return NONE.
6. -3%800 结果是 797
7. 35//10,是把35除以10,然后取小数点前面剩下的数
8. str(aaa) + str(bbb) +"1111" 是把这三个string 都连起来。
9. if elif else
10 在 function 里面解释, 用三个连续的 双引号“”“在前, 也用三个”“” 在后。叫做documentation。 解释这个方程式做什么的。 用comment也行。
11. x += y + x 意思是 x=x+y 然后再加上x。 和 x=x+y 意思不同。
if condition:
result
elif condition:
result
else:
result
要写 x ==1 or x == 2, 不能 x ==1 or 2
WEEK TWO
1. Events : Input; Keyboard; Mouse; Timer
2. there is a event queue in Python which we cannot see. event一个一个的执行,不能两个一起执行。如果同时出发两个事件(比如点鼠标和按键盘),python会形成一个Queue,一个一个执行。
3. 当event发生的时候,python 会去执行相对应的Handler.
4. all the variables created inside a function are called Local variables, it can only be used in the function.
5.如果在function 里定义一个和外面的variable一样名字的variable。在function里面按你定义的走,但是外面的不影响。
6. 挡在一个function里面要创建或调用一个global variable的话,就写出来 global number1
7. Program Structure: 1. Globals (State); 2. Helper Functions ;3 . Classes(Later)
4. Define event handlers; 5. create a frame; 6. register event handlers. 7. start frame & timers
8. simple gui 里面是里面 string input(text input), 要用 function int() 转换成integer number 或者用float() 来转换成floating point number.
9. 当写一个方程,没有说return什么东西的话。python会return NONE。 因为Python总是要return一个东西。
10. 写方程的时候,在每一步都加上print的输入和输出的东西,会是很好的debug工具。 最好还能加上lable
订阅:
博文 (Atom)