只是希望自己能够坚持学习,当个自己的学习笔记,难免有错
if语句:处理特殊情形
dimm=('a','b','c','d')
for dimm1 in dimm:
if dimm1 == 'b':
print(dimm1.upper())
else:
print(dimm1.lower())
a
B
c
d
if语句判断表达式时区分大小写
判断两个值是否不相等用!=
判断多个条件是否成立:and,or(类似于与门,或门)
检查特定值是否包含在列表中:'特定值' in 列表名
检查特定值是否不包含在列表中:not in 列表名:
检查超过两个以上的情形:if-elif-elif-...-elif-else:
if age<4:
price=0
elif age<18:
price=5
else:
price=10
print("Your admission cost is $"+ str(price)+".")
Your admission cost is .
使用多个列表:
for requested_topping in requested_toppings:
if requested_topping in available_toppings:
print("Adding "+requested_topping+".")
else:
print("Sorry,we don't have "+requested_topping+".")
print("\nFinished making your pizza!")
Sorry,we don't have v.
Finished making your pizza!
available_toppings=['a','b','c','d']
requested_toppings=['a','b','c']
for requested_topping in requested_toppings:
if requested_topping in available_toppings:
print("Adding "+requested_topping+".")
else:
print("Sorry,we don't have "+requested_topping+".")
print("\nFinished making your pizza!")、
Adding a.
Adding b.
Adding c.
Finished making your pizza!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)