1.datatype operator
Primary type:numbers strings booleans
Values-type每一个数据对应一个数据类型
运算符重载(overload) 3*’ab’//ok 3+’ab’//error
Type conversion:str(3)+’ab’
Type checking: 3<’a’
Operator precedence:
Assignment:
Dynamic types:动态类型
X=3
X=’ab’
x的类型随着表达式结果发生变化
Don’t change types arbitrarily!
2.Two good programming styles
Comments:对程序中间过程或运行结果的说明,在编写代码前先写注释
Variable names:具有某些特殊含义,不要使用关键字(keyword)
3.branching program
对某些数据进行测试,如果测试结果为True,执行一些指令,否则,执行另一些指令
if <some test>:
Blocks of instructions
else:
Blocks of instructions
x = 1
sum = 0
while x <= 100:
sum += x
x=x+1
print sum
x = 1
sum = 0
while x <= 100:
sum += x
x=x+1
print sum