Python学习之if循环

“”“Python if & while”""

1,if函数语句支持的数学条件

#函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段。
#== != > < >= <=
import random

age = random.randint(1, 101)
time = 100 - age

if age == time:
print(‘人到半百心犹盛’)
if age > time:
print(‘老当益壮气亦足’)
if age < time:
print(‘年少勇闯天下难’)

#这结果就是完全随机的了

2,list对比

test_num01 = [1, 3, 4, 5, 9]
test_num02 = [1, 3, 4, 5, 8]
if test_num01 == test_num02:
print(‘两个列表相等’)
if test_num01 != test_num02:
print(‘两个列表不相等’)

#两个列表不相等

3,字典对比

test_dict01 = {‘fruit’: ‘apple’, ‘plant’: ‘white poplar’}
test_dict02 = {‘plant’: ‘white poplar’, ‘fruit’: ‘apple’}
if test_dict01 == test_dict02:
print(‘两个字典相同’)
elif test_dict01

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值