Cov txheej txheem:

Kuv yuav txiav txim siab yam khoom hauv Python li cas?
Kuv yuav txiav txim siab yam khoom hauv Python li cas?

Video: Kuv yuav txiav txim siab yam khoom hauv Python li cas?

Video: Kuv yuav txiav txim siab yam khoom hauv Python li cas?
Video: nkauj huab lauj . koj tsis yuav kuv 2024, Hlis ntuj nqeg
Anonim

Yog ib qho kev sib cav ( khoom ) tau dhau mus hom () built-in, nws rov hom ntawm qhov muab khoom . Yog tias peb qhov kev sib cav (lub npe, lub hauv paus thiab cov lus txiav txim) dhau, nws rov qab los tshiab hom khoom . Yog koj xav tau txhawm rau txheeb xyuas hom khoom , nws raug pom zoo kom siv Python isinstance() ua haujlwm hloov.

Ib yam li ntawd, koj tuaj yeem nug, hom () hauv Python yog dab tsi?

Python | hom() muaj nuj nqi. hom() txoj kev rov qab chav kawm hom ntawm qhov kev sib cav (khoom) dhau li parameter. hom() muaj nuj nqi feem ntau yog siv rau kev debugging lub hom phiaj. Yog peb sib cav hom (npe, bases, dict) dhau lawm, nws rov los tshiab hom khoom.

Ib tug kuj yuav nug, Python yog ib yam khoom? Python yog ib khoom oriented programming lus. Tsis zoo li cov txheej txheem oriented programming, qhov tseem ceeb ntawm kev ua haujlwm, khoom oriented programming stress rau khoom . Yam khoom tsuas yog ib qho kev sau ntawm cov ntaub ntawv (kuj hloov pauv) thiab cov txheej txheem (kev ua haujlwm) uas ua rau cov ntaub ntawv no. Thiab, chav kawm yog ib daim ntawv qhia rau cov khoom.

Tsis tas li ntawd, lub luag haujlwm twg yog siv los txiav txim siab hom ntaub ntawv ntawm ib qho khoom hauv Python?

Tau qhov hom khoom : hom () hom () yog tus muaj nuj nqi uas rov qab hom khoom dhau mus rau kev sib cav. Koj ua tau siv qhov no rau nrhiav tawm ntawm hom khoom . Tus nqi rov qab los ntawm hom () yog hom ( hom khoom ) xws li str or int.

Dab tsi yog hom ntaub ntawv hauv Python?

Python txhawb nqa 4 hom ntaub ntawv tus lej

  • int (kos npe tus lej zoo li 10, 2, 29, thiab lwm yam)
  • ntev (cov lej ntev siv rau ntau qhov ntau dua ntawm qhov tseem ceeb xws li 908090800L, -0x1929292L, thiab lwm yam)
  • ntab (float yog siv los khaws cov naj npawb ntab ntab xws li 1.9, 9.902, 15.2, thiab lwm yam)
  • complex (xws li 2.14j, 2.0 + 2.3j, thiab lwm yam)

Pom zoo: