Python Duramazwi

Maduramazwi ndiwo makuru mepu mhando yatichazoshandisa muPython. Chinhu ichi chakafanana nemepu iri muJava.

MuPython, isu tinogadzira zvinyorwa zvemaduramazwi tichishandisa zvimicheto zvinyoro {}, kupatsanura makiyi kubva pamitengo uchishandisa makoloni :, uye kupatsanura makiyi / kukosha mapara uchishandisa makoma ,.

Maitiro Ekugadzira Duramazwi

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } print(datedict)

Kubuda:

{'date': 13, 'month': 'January', 'year': 1970}

Maitiro Ekuwana Duramazwi Zvinhu

Isu tinokwanisa kuwana duramazwi zvinhu nekureva kune iro kiyi zita mukati memakona mabhureki _ _ + _ | kana kushandisa [] nzira:

get()

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } date = datedict['date'] year = datedict.get('year') print(date, year)

Ungachinja Sei Kukosha Kwechimwe Chinhu

Tinogona kuchinja kukosha kwechinhu muduramazwi nekureva zita rayo rakakosha, semuenzaniso:



13 1970

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } datedict['date'] = 20 print(datedict)

Maitiro Ekusunungura kuburikidza Duramazwi

Tinogona kusunungura kuburikidza neduramazwi tichishandisa {'date': 20, 'month': 'January', 'year': 1970} chiuno. Kana tichisunungura kuburikidza neduramazwi, tinogona kupurinda makiyi ese, ese kukosha kana ese kiyi / kukosha mapara:

Tora Zvese Duramazwi Keys

for

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for d in datedict:
print(d)

Tora Zvese Duramazwi Maitiro

date month year

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for d in datedict:
print(datedict[d])

Tinogona zvakare kushandisa 13 January 1970 basa kudzorera kukosha:

values()

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for d in datedict.values():
print(d)

Tora maKiyi ese uye Maitiro muDuramazwi

Tinogona kushandisa 13 January 1970 basa kupurinda makiyi nemitengo:

items()

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } for k, v in datedict.items():
print(k, v)

Maitiro Ekuwana Kureba kweDuramazwi

Unogona kuwana duramazwi kureba (nhamba yemakiyi / kukosha mapara) nekufonera iyo date 13 month January year 1970 basa, i.k.

len()

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } print(len(datedict))

Maitiro Ekuwedzera Zvinhu kuDuramazwi

Kuwedzera kiyi / kukosha vaviri kuduramazwi tinoda kupa kiyi nyowani uye kukosha kwakabatana. Semuyenzaniso:

3

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970 } datedict['season'] = 'winter' print(datedict)

Maitiro Ekubvisa Zvinhu Kubva Kuduramazwi

Kuti ubvise chinhu kubva muduramazwi, govera iro kiyi zita ku {'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter'} nzira.

pop()

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter' } datedict.pop('season') print(datedict)

Tinogona zvakare kushandisa {'date': 13, 'month': 'January', 'year': 1970} kiyi yekudzima chinhu nekiyi yakatarwa:

del

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter' } del datedict['season'] print(datedict) Ongorora:Iyo of kiyi kiyi inogona zvakare kushandiswa kubvisa duramazwi zvachose. {'date': 13, 'month': 'January', 'year': 1970}

Maitiro Ekubvisa Iyo Duramazwi

Kuti udurure duramazwi kubva kune ese kiyi / kukosha mapara, shandisa datedict = { 'date': 13, 'month': 'January', 'year': 1970, } del datedict nzira

clear()

Kubuda:

datedict = { 'date': 13, 'month': 'January', 'year': 1970, 'season': 'winter' } datedict.clear() print(datedict)