python学习手册(5)

python初学者日记

1.python中检查是否相等区分大小写。两个大小写不同的值会视为不相等。如果在实际使用中想要忽略大小写,只判断字母是否相同时,可以用大写变量.lower()使其输出为小写。但并不会改变大写变量本身的值。
2.
相等==
不相等!=
3.
检查多个条件使用and,or:
例如:
if x!=0 and x<3 #两个测试都通过了才返回true
if x==0 or x>100 #只要一个条件满足就返回true
4.
检查某些值是否在数组里面:
设定数组为x=[‘apple’,‘pen’,‘orange’]
此时判断,pear是否在数组x里面:
if pear in x #pear在x里面,返回true
if pear not in x #pear不在x里面,返回true
5.
检查为一个时:
if —else
检查为多个时:
if—elif–else #有时else可省略
例子:
age=18
if age < 4:
print(“Your admission cost is $0.”)
elif age < 18:
print(“Your admission cost is $5.”)
elif age < 28:
print(“Your admission cost is $8.”)
else:
print(“Your admission cost is $10.”)
6.
进行多个不相关判断时:

例如:
if ‘mushrooms’ in requested_toppings:
print(“Adding mushrooms.”)
if ‘pepperoni’ in requested_toppings:
print(“Adding pepperoni.”)
if ‘extra cheese’ in requested_toppings:
print(“Adding extra cheese.”)
#满足哪几个条件,就执行哪几个命令

本次位置P77

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值