Python_list(四)列表if简单示范

/ Python / 没有评论 / 440浏览

if-else-slif结构

if和else和elif语句后面要添加冒号":"

if和else 一个简单的判断(带输入)

[root@pa1 lijinghua]# cat tiaojian.py 
#!/usr/bin/python
age = input('print enter your age:')
#print (name)
if age >= 18:
	print (r'She/He is adult')
else:
	print (r'She/He is teenager')

示范2

[root@pa1 lijinghua]#python if.py
BMW
Audi
Bigben
[root@pa1 lijinghua]#cat if.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
cars=['bmw','audi','bigben']
for car in cars:
        if car == 'bmw':
                print(car.upper()) #如果是宝马的话,全部大写
	else:
		print(car.title())  #如果不是的话,只是首字母大写

if和elif 示范

if和elif 示范

[root@pa1 lijinghua]# cat tiaojian2.py 
#!/usr/bin/python
age = input('print enter your age:')
#print (name)
if age >= 18:
	print (r'She/He is adult')
elif age >= 6:
	print (r'She/He is teenager')
else:
	print (r'She/He is kid' )