Python運算子總結筆記

2021-10-12 12:28:51 字數 843 閱讀 6652

算術運算子

比較運算子(== !=)

str 與 str 比較的是ascii值

'ax'

結果為true,因為兩者比較先比較a和x的ascii值,a的值小於x的值,所以返回true。

賦值運算子

成員運算子

身份運算子(id())

邏輯運算子

三目運算子

運算子優先順序

python 運算子優先順序和結合性一覽表

運算子說明

python運算子

優先順序優先順序順序

小括號( )19高

索引運算子

x[i] 或 x[i1: i2 [:i3]]18|

屬性訪問

x.attribute17|

乘方**16|

按位取反~15

|符號運算子

+(正號)、-(負號)14|

乘除*、/、//、%13|

加減+、-12|

、<<11|

按位與&10|

按位異或^9

|按位或|8

|比較運算子

==、!=、>、>=、

is 運算子

is、is not6|

in 運算子

in、not in5|

邏輯非not4|

邏輯與and3|

邏輯或or2|

逗號運算子

exp1, exp21低

Python運算子總結

運算子名稱 說明例子 加 兩個物件相加 3 5得到8。a b 得到 ab 減 得到負數或是乙個數減去另乙個數 5.2得到乙個負數。50 24得到26。乘 兩個數相乘或是返回乙個被重複若干次的字串 2 3得到6。la 3得到 lalala 冪 返回x的y次冪 3 4得到81 即3 3 3 3 除 x除...

python運算子總結

if name main x 1 if x 1 print true else print false x 1 y 2 等效於 x,y 1,2print x y 輸出結果 3if name main x,y 1,2print xprint x y print x y print x y print ...

python運算子總結

運算子 1算數運算子 在這裡插入 片x 1y 2print x y print x y print x y print x y print y x print y x print x y print y x 3 120.5020 2賦值運算子 簡單賦值運算 加法賦值運算 減法賦值運算 乘法賦值運算 ...