Python 全棧開發 python元組tuple

2022-08-10 03:42:08 字數 1315 閱讀 3286

什麼是元組:「元組就是乙個不可變的列表」 (並不是列表,只是為了便於記憶)

用途:用於存放多個值,只能讀不能二次賦值

表現形式:小括號()中間以逗號分割各個元素

eg:

tuples = ('

a','

b','

c','

d')

生成乙個簡單的元組

tuples = tuple(range(5))

print(tuples)    #結果(0, 1, 2, 3, 4)

len(tuple)

#

計算元組長度

tuples = (0, 1, 2, 3, 4)

print(len(tuples)) #

結果: 5

in 和not in

#

in 和not in

tuples = ('

a','

b','

c','d'

)print('a'

in tuples) #

結果:true

print('z'

in tuples) #

結果:false

print('x'

notin tuples) #

結果:true

print('d'

notin tuples) #

結果:false

元組的取值

#

元組的取值

tuples = ('

a','

b','

c','d'

)item =tuples[0]

print(item) #

結果:a

item = tuples[2]

print(item) #

結果:c

#while迴圈

c =0

while c print

(tuples[c])

c+=1

#for迴圈

for item in

tuples:

print(item)

關於元組的切片操作,在這裡不在贅述,請參考字串的切片。

python 全棧開發:python字串切片

Python 全棧開發 python內建函式

abs 對傳入引數取絕對值 bool 對傳入引數取布林值,none,0,這些引數傳入bool後,返回false all 所有傳入引數為真,才為真 any 任何乙個傳入引數為真,才為真 ascii 自動執行傳入引數的 repr 方法 將物件轉換為字串 bin 接收乙個十進位制,轉換成二進位制 oct ...

Python 全棧開發 python函式高階

函式的巢狀定義 def func1 print from func1 def func2 func2 記憶體位址 print from func2 print func2 func1 函式的巢狀呼叫 比較兩個數的大小 defmax2 x,y if x y return x else returny ...

Python 全棧開發 監控篇

如果你已經玩轉了 python 程式語言語法,肯定想用這些知識,開發一款應用程式,它可以是在網上,可以炫耀或 那就需要全棧式開發 python。具體如何建立,部署和執行生產 python web 應用程式,參考 full stack python,本文主要介紹一點,監控。為什麼要監控?web 應用程...