python测试开发预习课6/4

这篇博客介绍了Python中的逻辑运算符,包括and、or的用法,以及True和False的概念。接着讲解了如何判断字符串中数字和字母的个数,并实现相应条件的检查。此外,还探讨了十进制、二进制、八进制和十六进制的转换。最后,文章提到了序列取值的概念。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、与或非

(1)and:与,两个条件都是True,那么结果才是True。

2>1 and 3>1 —>True
True and True ----》True
True and False ----》False
False and True ----》False
False and False ----》False

>>> 2>1 and 3>1
True
>>> 2>1 and 3>4
False
>>> 2>3 and 3>1
False
>>> 2>3 and 3>4
False
>>> 2>3 and 3>4
False
>>> 2>3 and 3>4 and 5>1 and 10>8
False
>>> 4>3 and 3>4 and  5>1 and 10>8 and 9>1
False
>>> 4>3 and 5>4 and 5>1 and 10>8 and 9>1
True

在这里插入图片描述

(2)or:或,多个条件,只要一个是True,那么整个一组or都是True

True or True—>True
True or False—>True
False or True—>True
False or False—>False

>>> 2>1 or 3>1
True
>>> 2>1 or 1>2
True
>>> 1>2 or 2>1
True
>>> 1>2 or 1>3
False
>>> 2>1 or 0 or [] or {}
True
>>> False or 0 or [] or {}
{}
>>> bool(False or 0 or [] or {})
False
>>> 1==2 or 3==5 or 0 or  list
<class 'list'>

在这里插入图片描述

(3)True和false
>>> True
True
>>> False
False
>>> 2>1
True
>>> 1>2
False
>>> bool(1)
True
>>> bool(0)
False
>>> bool([])
False
>>> bool({})
False
>>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值