Python的流程控制

代码块缩进记得4个空格(sublime text3已经很聪明地帮我们做了,贴心)


1、If

height=176
if (height>170):
	print("哟不错哦")
if (height>175):
	print("挺高,妹子都喜欢")

2、if else

height=176
if (height<170):
	print("还能长吗?")
else:
	print("还好吧")

3、if elif

height=200
if (height<170):
	print("还能长吗?")
elif (height<175):	
	print("还好吧")
elif (height<180):
	print("不错哦")
else:
	print("太高找对象困难")	


4、for in 

list=("a","b","c")
for o in list:
	print(o)

list1=["a","b","c"]
for o in list1:
	print(o)

for i in range(1,101,1)
   print(i) #输出,1 2 3 4 .. 100


5、while 循环

i=0
while (True):
	i=i+1
	print(i)
	if (i>9):
		break
print ("next ..")

6、java/C里面的条件赋值实现:

age=19
title="小鲜肉" if age<=18 else "大叔"
print (title)

7、判断为假的如下面这些,但false不包括:

   False,[],0,{} 


没有case、switch这些,只能用if elif 实现。。。

你可能感兴趣的:(python)