python3基础3-if操作

#coding:utf-8
#允许汉语注释
#if
test = ['mushrooms', 'mushrooms', 'pineapple']
if test[0]==test[1]:
    print("ok")
else:
    print("no ok")

#检查某个元素是否在list里面
t = 'pineapple' in test
if t==True:
    print("true")

if 'pineapple1' not in test:
    print("true")

#检查list是否为空
if test:
    print("no empty")
else:
    print("empty")

age = 18
if age < 4:#在条件测试的格式设置方面,PEP 8提供的唯一建议是,在诸如== 、>= 和<= 等比较运算符两边各添加一个空格

    print("Your admission cost is $0.")
elif age < 18:
    print("Your admission cost is $5.")
else:
    print("Your admission cost is $10.")


发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>