最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

深入了解Python中運(yùn)算符函數(shù)的使用

 更新時(shí)間:2022年09月15日 17:02:33   作者:海擁  
Python?在“運(yùn)算符”模塊下為許多數(shù)學(xué)、邏輯、關(guān)系、按位等操作預(yù)定義了函數(shù)。本文介紹了一些基本功能,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下

Python 在“運(yùn)算符”模塊下為許多數(shù)學(xué)、邏輯、關(guān)系、按位等操作預(yù)定義了函數(shù)。本文介紹了一些基本功能。

1. add(a, b)  :- 這個(gè)函數(shù)返回給定參數(shù)的加法。

操作 - a + b。

2. sub(a, b)  :- 此函數(shù)返回給定參數(shù)的差異

操作 - a - b。

3. mul(a, b)  :- 這個(gè)函數(shù)返回給定參數(shù)的乘積

操作 - a * b。

# 演示 add()、sub()、mul() 工作的 Python 代碼

# importing operator module
import operator

# 初始化變量
a = 4

b = 3

# 使用 add() 將兩個(gè)數(shù)字相加
print ("The addition of numbers is :",end="");
print (operator.add(a, b))

# 使用 sub() 減去兩個(gè)數(shù)字
print ("The difference of numbers is :",end="");
print (operator.sub(a, b))

# 使用 mul() 將兩個(gè)數(shù)字相乘
print ("The product of numbers is :",end="");
print (operator.mul(a, b))

輸出:

The addition of numbers is:7
The difference of numbers is :1
The product of numbers is:12

4. truediv(a,b)  :- 這個(gè)函數(shù)返回給定參數(shù)的除法。

操作 - a / b。

5. floordiv(a,b)  :- 此函數(shù)還返回給定參數(shù)的除法。但該值是下限值,即返回最大的小整數(shù)

操作 – a // b。

6. pow(a,b)  :- 這個(gè)函數(shù)返回給定參數(shù)的。

操作 – a ** b.

7. mod(a,b)  :- 這個(gè)函數(shù)返回給定參數(shù)的模數(shù)。操作 – a % b.

# 演示 truediv()、floordiv()、pow()、mod() 工作的 Python 代碼

# importing operator module
import operator

# 初始化變量
a = 5

b = 2

# 使用 truediv() 將兩個(gè)數(shù)字相除
print ("The true division of numbers is : ",end="");
print (operator.truediv(a,b))

# 使用 floordiv() 將兩個(gè)數(shù)字相除
print ("The floor division of numbers is : ",end="");
print (operator.floordiv(a,b))

# 使用 pow() 對兩個(gè)數(shù)字求冪
print ("The exponentiation of numbers is : ",end="");
print (operator.pow(a,b))

# 使用 mod() 取兩個(gè)數(shù)的模
print ("The modulus of numbers is : ",end="");
print (operator.mod(a,b))

輸出:

The true division of numbers is: 2.5
The floor division of numbers is: 2
The exponentiation of numbers is: 25
The modulus of numbers is: 1

8. lt(a, b)  :- 此函數(shù)用于檢查 a 是否小于 b。如果 a 小于 b,則返回 true,否則返回 false。

操作 - a < b。

9. le(a, b)  :- 此函數(shù)用于檢查 a 是否小于或等于 b。如果 a 小于或等于 b,則返回 true,否則返回 false。

操作 - a <= b。

10. eq(a, b)  :- 此函數(shù)用于檢查 a 是否等于 b。如果 a 等于 b,則返回 true,否則返回 false。

操作 - a == b

# 演示 lt()、le() 和 eq() 工作的 Python 代碼

# importing operator module
import operator

# 初始化變量
a = 3

b = 3

# 使用 lt() 檢查 a 是否小于 b
if(operator.lt(a,b)):
	print ("3 is less than 3")
else : print ("3 is not less than 3")

# 使用 le() 檢查 a 是否小于或等于 b
if(operator.le(a,b)):
	print ("3 is less than or equal to 3")
else : print ("3 is not less than or equal to 3")

# 使用 eq() 檢查 a 是否等于 b
if (operator.eq(a,b)):
	print ("3 is equal to 3")
else : print ("3 is not equal to 3")

輸出:

3 is not less than 3
3 is less than or equal to 3
3 is equal to 3

11. gt(a,b)  :- 此函數(shù)用于檢查 a 是否大于 b。如果 a 大于 b,則返回 true,否則返回 false。

操作 - a > b

12. ge(a,b)  :- 此函數(shù)用于檢查 a 是否大于或等于 b。如果 a 大于或等于 b,則返回 true,否則返回 false。

操作 - a >= b

13. ne(a,b)  :- 此函數(shù)用于檢查 a 是否不等于 b 或是否相等。如果 a 不等于 b,則返回 true,否則返回 false。

操作 - a != b。

# 演示 gt()、ge() 和 ne() 工作的 Python 代碼

# importing operator module
import operator

# 初始化變量
a = 4

b = 3

# 使用 gt() 檢查 a 是否大于 b
if (operator.gt(a,b)):
	print ("4 is greater than 3")
else : print ("4 is not greater than 3")

# 使用 ge() 檢查 a 是否大于或等于 b
if (operator.ge(a,b)):
	print ("4 is greater than or equal to 3")
else : print ("4 is not greater than or equal to 3")

# 使用 ne() 檢查 a 是否不等于 b
if (operator.ne(a,b)):
	print ("4 is not equal to 3")
else : print ("4 is equal to 3")

輸出:

4 is greater than 3
4 is greater than or equal to 3
4 is not equal to 3

到此這篇關(guān)于深入了解Python中運(yùn)算符函數(shù)的使用的文章就介紹到這了,更多相關(guān)Python運(yùn)算符函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python利用matplotlib繪制折線圖的新手教程

    Python利用matplotlib繪制折線圖的新手教程

    這篇文章主要給大家介紹了關(guān)于Python利用matplotlib繪制折線圖的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • tensorflow使用CNN分析mnist手寫體數(shù)字?jǐn)?shù)據(jù)集

    tensorflow使用CNN分析mnist手寫體數(shù)字?jǐn)?shù)據(jù)集

    這篇文章主要介紹了tensorflow使用CNN分析mnist手寫體數(shù)字?jǐn)?shù)據(jù)集,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • 刪除PyCharm解釋器的方法步驟

    刪除PyCharm解釋器的方法步驟

    這篇文章主要給大家介紹了關(guān)于刪除PyCharm解釋器的方法步驟,PyCharm解釋器是指在PyCharm集成開發(fā)環(huán)境中用于運(yùn)行和調(diào)試Python代碼的解釋器,需要的朋友可以參考下
    2023-09-09
  • Python操作PDF實(shí)現(xiàn)制作數(shù)據(jù)報(bào)告

    Python操作PDF實(shí)現(xiàn)制作數(shù)據(jù)報(bào)告

    Python操作PDF的庫有很多,比如PyPDF2、pdfplumber、PyMuPDF等等。本文將利用FPDF模塊操作PDF實(shí)現(xiàn)制作數(shù)據(jù)報(bào)告,感興趣的小伙伴可以嘗試一下
    2022-12-12
  • python如何實(shí)現(xiàn)單向鏈表及單向鏈表的反轉(zhuǎn)

    python如何實(shí)現(xiàn)單向鏈表及單向鏈表的反轉(zhuǎn)

    這篇文章主要介紹了python如何實(shí)現(xiàn)單向鏈表及單向鏈表的反轉(zhuǎn),幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • Python基礎(chǔ)知識(shí)之推導(dǎo)式詳解

    Python基礎(chǔ)知識(shí)之推導(dǎo)式詳解

    這篇文章主要介紹了Python基礎(chǔ)知識(shí)之推導(dǎo)式詳解,Python推導(dǎo)式是一種簡潔高效的代碼編寫方式,可以用一行代碼來創(chuàng)建列表、集合、字典等復(fù)雜數(shù)據(jù)結(jié)構(gòu),需要的朋友可以參考下
    2023-07-07
  • Python中bisect的使用方法

    Python中bisect的使用方法

    這篇文章主要介紹了Python中bisect的使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • 最新評論

    通州区| 伊宁市| 怀宁县| 黄陵县| 宜兰县| 婺源县| 桐城市| 濉溪县| 通榆县| 砀山县| 大城县| 西充县| 蒙城县| 兰考县| 吉林省| 澄城县| 大埔县| 磐安县| 策勒县| 浮梁县| 大足县| 彰武县| 怀柔区| 依兰县| 和静县| 克拉玛依市| 岳阳县| 华宁县| 东兴市| 兴安县| 怀集县| 黄大仙区| 和平县| 新宁县| 白银市| 成安县| 始兴县| 唐山市| 枣强县| 吉首市| 东方市|