Cov kev hloov pauv ua haujlwm li cas hauv Python?
Cov kev hloov pauv ua haujlwm li cas hauv Python?

Video: Cov kev hloov pauv ua haujlwm li cas hauv Python?

Video: Cov kev hloov pauv ua haujlwm li cas hauv Python?
Video: Finance with Python! Short Selling and Short Positions 2024, Tej zaum
Anonim

A Python variable yog lub cim lub npe uas yog siv los yog taw tes rau ib yam khoom. Thaum ib yam khoom raug muab rau a sib txawv , koj tuaj yeem xa mus rau qhov khoom los ntawm lub npe ntawd. Tab sis cov ntaub ntawv nws tus kheej tseem nyob hauv qhov khoom.

Object References

  • Tsim ib qho khoom muaj pes tsawg leeg.
  • Muab nws tus nqi 300.
  • Qhia nws rau lub console.

Ib sab ntawm qhov no, koj siv cov kev hloov pauv hauv Python li cas?

Python yog dynamically typed, uas txhais tau hais tias koj tsis tas yuav tshaj tawm hom twg sib txawv yog. Hauv Python , sib txawv yog qhov chaw cia rau cov ntawv thiab cov lej. Nws yuav tsum muaj lub npe kom koj thiaj li nrhiav tau nws dua. Cov sib txawv yog ib txwm muab nrog lub cim sib npaug, ua raws li tus nqi ntawm tus sib txawv.

Kuj Paub, koj ua li cas tso saib qhov sib txawv hauv Python? Hloov pauv tuaj yeem pom ntawm qhov screen uas siv cov ntawv luam tawm. Thawj tso zis ntawm qhov kev pab cuam saum toj no tsuas yog tus nqi raw ntawm cov sib txawv . Yog tias koj xav luam cov lus qhia ntxaws ntxiv xws li: "x = 5", siv kab 'print("x = " + str(x))'.

Yog li ntawd, koj muab qhov sib txawv li cas rau qhov ua haujlwm hauv Python?

Koj tsuas tsis hu tus muaj nuj nqi . Cov kab lus qhia python uas koj hu lub muaj nuj nqi , yog li thaum koj muab lawv tso rau ntawd, nws hu rau muaj nuj nqi thiab muab y tus nqi xa rov qab los ntawm x (uas yog qhov no tsis muaj). Thaum koj muab a muaj nuj nqi rau a sib txawv koj tsis siv tus () tab sis tsuas yog lub npe ntawm tus muaj nuj nqi.

Dab tsi yog _ hloov pauv hauv Python?

Double Underscore(_) _leading_double_underscore. Ua ob underscore qhia python tus neeg txhais lus rov sau lub npe kom tsis txhob muaj teeb meem hauv subclass. Tus txhais lus hloov sib txawv lub npe nrog cov chav kawm txuas ntxiv thiab qhov tshwj xeeb hu ua Mangling.

Pom zoo: