日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python booleans_Python 2.1 BooleansComparisons

發(fā)布時間:2025/4/16 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python booleans_Python 2.1 BooleansComparisons 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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。

它們可以通過比較值來創(chuàng)建,例如使用等號操作符==。

>>> 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也有一些運算符來確定一個數(shù)字(浮點數(shù)或整數(shù))是大于還是小于另一個。這些操作符分別是>和

>>> 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

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

它們與嚴格的大于和小于操作符相同,只是在比較相等的數(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).

大于和小于操作符還可以用于按字典順序比較字符串(單詞的字母順序基于其組成字母的字母順序)。

總結

以上是生活随笔為你收集整理的python booleans_Python 2.1 BooleansComparisons的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。