python基础--7.简单的if判断

'''
and 并且
or 或者
'''
colors = ['red','blue','black','green']
for color in colors:
	if color == 'black':
		print('black')
	else:
		print('not black')
out:
not black
not black
black
not black
for color in colors:
	if color == 'black':
		break        # 跳出大循环
		print('black')
	else:
		print('not black')
out:
not black
not black
for color in colors:
	if color == 'black':
		continue        # 跳出当前循环
		print('black')
	else:
		print('not black')
out:
not black
not black
not black
if 'red' in colors: #判断列表中是否有‘red’,返回值是true/false
	print('red')
out:red
null = []
if null: #判断列表是否为空,有值返回true,空的话返回false
	print(1)
else:
	print(0)
out:0
#if可以判断字符串的大小
if 'ann'<'bgg':
	print(1)
else:
	print(0)
上一篇:Flutter_03_画一个按钮和一根线


下一篇:Swift 团队开源 Collections,提供更多高效数据结构