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).
大于和小于操作符还可以用于按字典顺序比较字符串(单词的字母顺序基于其组成字母的字母顺序)。