python booleans_Python 2.1 Booleans&Comparisons

Booleans#布尔值

Another type in Python is the Boolean type.There are two Boolean values: True and False.

They can be created by comparing values, for instance by using the equal operator ==.

>>> my_boolean = True

>>> my_boolean

True

>>> 2 == 3

False

>>> "hello" == "hello"

True

Python中的另一种类型是布尔类型。有两个布尔值:True和False。

它们可以通过比较值来创建,例如使用等号操作符==。

>>> my_boolean = True

>>> my_boolean

True

>>> 2 == 3

False

>>> "hello" == "hello"

True

Be careful not to confuse assignment (one equals sign) with comparison (two equals signs).

注意不要混淆赋值(一个等号)和比较(两个等号)。

Comparison#比较

Another comparison operator, the not equal operator (!=), evaluates to True if the items being compared aren't equal, and False if they are.

>>> 1 != 1

False

>>> "eleven" != "seven"

True

>>> 2 != 10

True

另一个比较操作符not equal操作符(!=)在被比较的项不相等时计算为True,如果相等则为False。

>>> 1 != 1

False

>>> "eleven" != "seven"

True

>>> 2 != 10

True

Python also has operators that determine whether one number (float or integer) is greater than or smaller than another.These operators are > and < respectively.

>>> 7 > 5

True

>>> 10 < 10

False

Python也有一些运算符来确定一个数字(浮点数或整数)是大于还是小于另一个。这些操作符分别是>和

>>> 7 > 5

True

>>> 10 < 10

False

The greater than or equal to, and smaller than or equal to operators are >= and <=.

They are the same as the strict greater than and smaller than operators, except that they return True when comparing equal numbers.

>>> 7 <= 8

True

>>> 9 >= 9.0

True

大于或等于、小于或等于运算符的是>=和<=。

它们与严格的大于和小于操作符相同,只是在比较相等的数字时返回True。

>>> 7 <= 8

True

>>> 9 >= 9.0

True

Greater than and smaller than operators can also be used to compare strings lexicographically (the alphabetical order of words is based on the alphabetical order of their component letters).

大于和小于操作符还可以用于按字典顺序比较字符串(单词的字母顺序基于其组成字母的字母顺序)。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值