第七章 基本資料型別(tuple)

2022-09-12 10:39:13 字數 1875 閱讀 3960

tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33)

for item in tuple_test:

print(item)

"""返回的結果

1020

30['list', 'jim', 'mary', (123, 'xuhongmei')]

true

33"""

tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33)

tuple_test[3][3]="yx"

print(tuple_test)

"""返回的結果

(10, 20, 30, ['list', 'jim', 'mary', 'yx'], true, 33)

"""tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33)

print(tuple_test)

"""返回的結果

(10, 20, 30, ['list', 'jim', 'mary', (123, 'xuhongmei'), 'yuxianming'], true, 33)

"""del tuple_test[0]

print(tuple_test)

"""返回結果報錯

nameerror: name 'tuple_test' is not defined

"""tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33)

v=tuple_test[3][3]

print(v)

"""返回的結果

(123, 'xuhongmei')

"""tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33)

v1=tuple_test[1:3]

print(v1)

"""返回的結果

(20, 30)

"""tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33)

v2=list(tuple_test)

print(v2)

"""返回的結果

[10, 20, 30, ['list', 'jim', 'mary', (123, 'xuhongmei')], true, 33]

"""str_test=""

for item in tuple_test:

item=str(item)

str_test=str_test+item

print(str_test)

"""返回的結果

102030['list', 'jim', 'mary', (123, 'xuhongmei')]true33

"""tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,33,33,20,10)

v3=tuple_test.count(10)

print(v3)

"""返回的結果

2"""

tuple_test=(10,20,30,["list","jim","mary",(123,"xuhongmei")],true,10,33,20,10)

v4=tuple_test.index(10,2,8) 從下標2位置開始一直到8,第1個出現"10"的索引位置是5

print(v4)

"""返回結果

5"""

第七章 資料過濾

表名 products 字段 product id product name product price vend id 商 為了提供更強的過濾控制,mysql允許給出多個where子句,zhe這些子句可以以 and子句和or子句的方式使用。注 操作符 operator 用來聯結或改變where子句...

第七章 String型別相關

1 如何建立string型別物件 string str abc 最常用 string string new string 建立乙個物件 string string new string abc 建立兩個物件,乙個為abc字串物件,乙個為new string 2 字串剪下 substring 1,3 ...

第七章 對映與集合型別

方法一dict1 dict2 print dict1,dict2結果 方法二 用dict fdict dict x 1 y 2 print fdict結果方法三 fromkeys ddict fromkeys x y 1 print ddict結果例子dict2 for key in dict2.k...