#建立乙個空字典empty_dict =dict()
print(empty_dict)
#用**kwargs可變引數傳入關鍵字建立字典
a = dict(one=1,two=2,three=3
) print(a)
#傳入可迭代物件
b = dict(zip(['
one','
two','
three
'],[1,2,3
]))print(list(zip([
'one
','two
','three
'],[1,2,3
])))
print(b)
#傳入可迭代物件
c = dict([('
one', 1), ('
two', 2), ('
three
', 3
)])print(c)
c1 = dict([('
one', 1), ('
two', 2), ('
three
', 3),('
three
', 4),('
three
', 5
)])print(c1)#如果鍵有重複,其值為最後重複項的值。
#傳入對映物件,字典建立字典
d = dict()
print(d)
print(a == b == c ==d)
複製**
輸出:{}[('
one', 1), ('
two', 2), ('
three
', 3
)]true
複製**
python的三種建立字典的方法
建立乙個空字典 empty dict dict print empty dict 用 kwargs可變引數傳入關鍵字建立字典 a dict one 1,two 2,three 3 print a 傳入可迭代物件 b dict zip one two three 1,2,3 print list zi...
執行緒的三種建立方
一,繼承thread 重寫run class programmer extends thread public static void main string args 二,繼承runnable 實現run class programmer implements runnable public st...
Spark建立DataFrame的三種方式
package blog import org.apache.spark.sql.import org.apache.spark.sql.types.author daniel description scala建立dataframe的三種方式 object createdataframe impo...