day03-python基本语句

1.1分支语句if

a=1
b=2
if a==b:
	print('true')
else:
print('flase')

if a<b:
	print('true')
else:
	print('flase')
#基本语句
if<条件>if<条件><语句>
	else:
		<语句>
elif<条件>:
	if<条件><语句>
else<语句>

1.2循环结构for语句:

#结构
for<> in <对象集合>if<条件>break
	if<条件>continue
else<>
#示例代码
for i in [1,2,3,4,5]:
	if i == 6:
		break
	if i == 2:
		continue
	print(i)
	else:
	print('all')
	#for语句中的对象集合可以是列表,字典或元组。也可以通过range()函数产生一个整数列表
	#示例代码
	for i in range(1,5+1):
		print(i)
people = {'Tom':170,'jack':160,'kite':160}
for name in people:
print(people[name])

1.3循环结构while语句:

#结构示例
while<条件>if<条件>break
	if<条件>:
		continue
else<语句>

#示例代码:
x = 1
while x <=5:
print(x)
x = x+1
发布了23 篇原创文章 · 获赞 0 · 访问量 508

猜你喜欢

转载自blog.csdn.net/weixin_46244909/article/details/104247047