python booleans_Python 2.1 BooleansComparisons
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中的另一種類型是布爾類型。有兩個(gè)布爾值:True和False。
它們可以通過比較值來創(chuàng)建,例如使用等號(hào)操作符==。
>>> 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).
注意不要混淆賦值(一個(gè)等號(hào))和比較(兩個(gè)等號(hào))。
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
另一個(gè)比較操作符not equal操作符(!=)在被比較的項(xiàng)不相等時(shí)計(jì)算為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也有一些運(yùn)算符來確定一個(gè)數(shù)字(浮點(diǎn)數(shù)或整數(shù))是大于還是小于另一個(gè)。這些操作符分別是>和
>>> 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
大于或等于、小于或等于運(yùn)算符的是>=和<=。
它們與嚴(yán)格的大于和小于操作符相同,只是在比較相等的數(shù)字時(shí)返回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).
大于和小于操作符還可以用于按字典順序比較字符串(單詞的字母順序基于其組成字母的字母順序)。
總結(jié)
以上是生活随笔為你收集整理的python booleans_Python 2.1 BooleansComparisons的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: thymeleaf依赖_玩转Spring
- 下一篇: http在链接中加入用户名_爬虫基础——