Izichazi magama zezona ziluhlobo oluphambili lweemaphu esiya kulusebenzisa ePython. Le nto iyafana nemephu kwiJava.
KwiPython, senza iilwimi zesichazi-magama ngokusebenzisa ii-curly brace {}
, ukwahlula amaqhosha kumaxabiso usebenzisa iikholoni :
, nokwahlulahlula isitshixo / sexabiso sexabiso usebenzisa iikhoma ,
.
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } print(datedict)
Iziphumo:
{'date': 13, 'month': 'January', 'year': 1970}
Singafikelela kwizinto zesichazi-magama ngokubhekisa kwigama eliphambili ngaphakathi kwizibiyeli ezisisikwere []
okanye usebenzisa get()
indlela:
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } date = datedict['date'] year = datedict.get('year') print(date, year)
Iziphumo:
13 1970
Singalitshintsha ixabiso lento ethile kwisichazi-magama ngokubhekisa kwigama layo eliphambili, umzekelo:
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } datedict['date'] = 20 print(datedict)
Iziphumo:
{'date': 20, 'month': 'January', 'year': 1970}
Singakwazi ukuvula isichazi-magama sisebenzisa for
loop. Xa ujikeleza kwisichazi-magama, sinokuprinta onke amaqhosha, onke amaxabiso okanye onke amaqhosha / amaxabiso abalulekileyo:
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for d in datedict:
print(d)
Iziphumo:
date month year
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for d in datedict:
print(datedict[d])
Iziphumo:
13 January 1970
Sinokusebenzisa kwakhona values()
function ukubuyisa amaxabiso:
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for d in datedict.values():
print(d)
Iziphumo:
13 January 1970
Singasebenzisa items()
sebenza ukuprinta amaqhosha kunye namaxabiso:
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for k, v in datedict.items():
print(k, v)
Iziphumo:
date 13 month January year 1970
Ungabufumana ubude besichazi-magama (inani lamaqhosha / amaxabiso amaxabiso) ngokubiza len()
umsebenzi, o.k.t.
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } print(len(datedict))
Iziphumo:
3
Ukongeza isitshixo / ixabiso lesibini kwisichazi-magama kufuneka sinike isitshixo esitsha kunye nexabiso elinxulumene noko. Umzekelo:
datedict = { 'date': 13, 'month': 'January', 'year': 1970 } datedict['season'] = 'winter' print(datedict)
Iziphumo:
{'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter'}
Ukususa into kwisichazi-magama, nikezela ngegama eliphambili kwi pop()
indlela.
datedict = { 'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter' } datedict.pop('season') print(datedict)
Iziphumo:
{'date': 13, 'month': 'January', 'year': 1970}
Sinokusebenzisa kwakhona del
igama eliphambili ukucima into ngesitshixo esichaziweyo:
datedict = { 'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter' } del datedict['season'] print(datedict)
Iziphumo:
{'date': 13, 'month': 'January', 'year': 1970}
Phawula:Inkqubo ye- ye igama eliphambili linokusetyenziselwa ukususa isichazi-magama ngokupheleleyo. datedict = { 'date': 13, 'month': 'January', 'year': 1970, } del datedict
Ukukhupha isichazi-magama kuzo zonke izitshixo / ixabiso lezibini, sebenzisa clear()
indlela
datedict = { 'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter' } datedict.clear() print(datedict)
Iziphumo:
{}