Koj siv IF nqe lus li cas hauv Python?
Koj siv IF nqe lus li cas hauv Python?

Video: Koj siv IF nqe lus li cas hauv Python?

Video: Koj siv IF nqe lus li cas hauv Python?
Video: Finance with Python! Portfolio Diversification and Risk 2024, Kaum ib hlis
Anonim

Hauv Python , Yog Hais Lus yog siv kev txiav txim siab. Nws yuav khiav lub cev ntawm code xwb thaum IFstatement yog muaj tseeb. Thaum twg koj xav kom pom tseeb ib qho xwm txheej thaum lwm qhov xwm txheej tsis muaj tseeb, ces koj siv " yog hais tias ". Code Kab 8: Qhov sib txawv st isset rau "x yog tsawg dua y."

Ib yam li ntawd ib tug yuav nug, YOG THAUM nqe lus dab tsi?

Ib feem tom qab " yog ": koj tau qhab nia zoo - hu ua ib qho kev xav thiab ib feem tom qab " ces " - koj yuav nkag mus rau hauv ib lub tsev kawm ntawv zoo - hu ua qhov xaus. Yog - nqe lus ntawd los yog conditional nqe lus.

Ib sab saum toj no, dab tsi yog ib daim ntawv qhia IF? Qhov thaiv ntawm code tom qab lwm tus nqe lus isexecuted raws li tus mob tam sim no nyob rau hauv lub yog hais tias yog cuav. ua zes - yog . A nested yog yog ib ifstatement uas yog lub hom phiaj ntawm lwm tus yog hais tias . Nested yog cov lus txhais tau tias ib yog hais tias sab hauv yog hais tias.

Raws li txoj cai, cov lus tswj hwm hauv python yog dab tsi?

Tswj cov lus hauv python siv los tswj qhov kev txiav txim ntawm kev ua tiav ntawm qhov kev pab cuam raws li tus nqi thiab cov logic. Python muab peb 3 hom Tswj Cov Lus Qhia : Mus ntxiv. So.

Dab tsi yog qhov rov qab ntawm nqe lus?

Rov qab ntawm ib tug Conditional. Negating ob qhov kev xav thiab qhov xaus ntawm qhov xwm txheej nqe lus . Piv txwv li, lub thim rov qab ntawm "Yog los nag ces nyom nyom" yog "Yog tsis los nag ces nyom tsis ntub". Nco tseg: Raws li qhov piv txwv, qhov kev xav yuav muaj tseeb tab sis nws thim rov qab tej zaum yuav tsis muaj tseeb. Saib thiab.

Pom zoo: