Peb puas tuaj yeem muaj tib tus yuam sij hauv phau ntawv txhais lus python?
Peb puas tuaj yeem muaj tib tus yuam sij hauv phau ntawv txhais lus python?

Video: Peb puas tuaj yeem muaj tib tus yuam sij hauv phau ntawv txhais lus python?

Video: Peb puas tuaj yeem muaj tib tus yuam sij hauv phau ntawv txhais lus python?
Video: Mathematics with Python! Sequences 2024, Kaum ib hlis
Anonim

Teb. Tsis yog, txhua tus yuam sij hauv a phau ntawv txhais lus yuav tsum yog tus tshwj xeeb. Koj ua tau 't muaj ob yuam sij nrog rau ib yam tus nqi. Sim siv lub tib tus yuam sij dua yuav tsuas yog overwrite tus nqi yav dhau los khaws cia.

Hauv qhov no, koj puas tuaj yeem muaj cov yuam sij sib npaug hauv phau ntawv txhais lus python?

Python phau ntawv txhais lus map a tus yuam sij mus rau tus nqi. Luam cov yuam sij tsis tso cai, thiab cov khoom tshiab hloov cov qub qub nrog tib yam tus yuam sij . Kev txiav txim tsis yog txwv tsis pub, yog li tsis muaj txoj hauv kev tau cov khoom hauv qhov kev txiav txim lawv tau ntxiv rau a phau ntawv txhais lus.

Qhov thib ob, koj yuav ua li cas xyuas seb tus yuam sij puas nyob hauv phau ntawv txhais lus python? Kom yooj yim xyuas seb puas muaj tus yuam sij muaj nyob rau hauv ib Python phau ntawv txhais lus koj tuaj yeem siv tus neeg teb xov tooj los tshawb nrhiav los ntawm cov phau ntawv txhais lus zoo li no: tsiaj = {'cats': 1, 'dub': 2, 'ntses': 3} yog ' dev' hauv tsiaj: luam tawm ('Dog pom!') # dev pom!

Kuj nug, pes tsawg tus yuam sij zoo ib yam tuaj yeem muaj phau ntawv txhais lus muaj Python?

Ntau tus yuam sij zoo ib yam hauv a Python dict - yog, koj ua tau ! Ntau tus yuam sij zoo ib yam hauv a Python dict - yog, koj ua tau ! Yog koj muaj lis,tu ua tau nkaus xwb muaj ib lub caij ntawm txhua tus lej - tsuas yog ib qho positon [0], ib qho [1] thiab lwm yam. Qhov ntawd yog qhov tseeb, thiab ntuj kom nkag siab.

Puas yog phau ntawv txhais lus tseem ceeb tuaj yeem yog npe Python?

Lub builtin lis hom yuav tsum tsis txhob siv raws li ib tug tus yuam sij phau ntawv txhais lus . Nco ntsoov tias txij li cov tuples tsis hloov pauv, lawv ua tsis khiav mus rau qhov teeb meem ntawm cov npe - lawv ua tau tau hashed los ntawm lawv cov ntsiab lus tsis muaj kev txhawj xeeb txog kev hloov kho. Yog li ntawd, hauv Python , lawv muab txoj kev siv tau _hash_, thiab yog li siv tau li cov phau ntawv txhais lus.

Pom zoo: