python快速入门(4)判断结构

1.bool类型
cat = False
dog = True
print(type(cat))
print(type(dog))
2.判断
print(8 == 8)
3.判断List中元素大小
month = [1,2,5,4]
print(month[2]>month[1])

4.if else语句
if condition:(if后面加上判断的条件,可以先用一个变量定义判断条件)
else:
或者用if 1:
>0在python里面对应True
=0代表False
也可以写两个if不写else

5.在list当中查找元素
用for循环
name = ['roy','cao','yue']
for i in name:
    if i  == 'cao':
        print('cao found')

不用for循环
name = ['roy','cao','yue']
cao = 'cao1' in name
print(cao)

判断指定元素在不在List中:

猜你喜欢

转载自blog.csdn.net/qq_36477562/article/details/74276512