>>> False==True False >>> False==False True >>> not False True >>> False and False False >>> False and True False >>> False or True True布尔运算的优先级(从高到低)
pwd=input(‘please input the password: ‘)
if pwd==‘admin‘:
print ‘success!‘
else:
print ‘error!‘
score=int(input(‘please input the score: ‘))
if score>=90:
print ‘A‘
elif 80<=score<90:
print ‘B‘
elif 60<=score<70:
print ‘C‘
else:
print ‘D‘
pets=[‘dog‘,‘cat‘,‘pig‘]
for i in range(len(pets)):
print pets[i]
>>> dog cat pig
>>> while i<10: print i i=i+1 #Python中没有 ++ -- 2 3 4 5 6 7 8 9
total=0
while True:
if total<100:
total=total+2
else:
total=total-2
break
print total
import math def area(r): ‘‘‘ return the area of a cicle ‘‘‘ return math.pi*r**2函数,变量的命名规则与其他高级语言一样的。
>>>print(area.__doc__) return the area of a circle要注意变量的作用域!!!
def greet(name,greeting=‘hello‘):
.... 3)创建模块import myfile dir(myfile)
Python学习(二):入门篇:python中流程控制与函数编写,布布扣,bubuko.com
Python学习(二):入门篇:python中流程控制与函数编写
原文:http://blog.csdn.net/jxlijunhao/article/details/24876025