Python学习笔记3—if语句

2017-12-16  本文已影响0人  肉松饼饼

一、简单知识点

二、if语句

if conditional_test:
    do something
if conditional_test:
    do A
else:
    do B
if conditional_test1:
    do A
elif conditional_test2:
    do B
else:
    do C
if conditional_test1:
    do A
if conditional_test2:
    do B

注:

三、使用if语句处理列表

1、检查特殊元素

for name in names:
     if name == 'Tom':
         print("Hi," + name )
    else:
         print("Hello," + name)

2、确定列表不是空的

names = []
if names:
    for name in names:
        print(name)
else:
    print("sorry,the names is empty!")

3、使用多个列表

for name in names:
    if name in another_names:
        print("Welcome " + name)
    else:
        print("Sorry," + name)
上一篇下一篇

猜你喜欢

热点阅读