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

来源:互联网 发布:如东知品服饰有限公司 编辑:程序博客网 时间:2024/06/06 03:44
1.bool类型
cat = Falsedog = Trueprint(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 nameprint(cao)

判断指定元素在不在List中:
原创粉丝点击