Vim li cas cov tshuab hluav taws xob muaj txiaj ntsig?
Vim li cas cov tshuab hluav taws xob muaj txiaj ntsig?

Video: Vim li cas cov tshuab hluav taws xob muaj txiaj ntsig?

Video: Vim li cas cov tshuab hluav taws xob muaj txiaj ntsig?
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Tej zaum
Anonim

Cov tshuab hluav taws xob tau yog ib feem tseem ceeb ntawm Python txij li thaum lawv tau qhia nrog PEP 255. Lub tshuab hluav taws xob cov haujlwm tso cai rau koj tshaj tawm cov haujlwm uas coj tus cwj pwm zoo li tus iterator. Lawv tso cai rau cov programmer los ua tus iteration hauv txoj kev nrawm, yooj yim, thiab huv. Ib qho iterator yog ib yam khoom uas tuaj yeem rov ua dua (looped) rau.

Ntawm no, dab tsi yog lub luag haujlwm ntawm txhua lub tshuab hluav taws xob?

Hauv computer science, a lub tshuab hluav taws xob yog ib lub sij hawm uas yuav siv tau los tswj tus cwj pwm iteration ntawm ib lub voj. Txhua lub tshuab hluav taws xob kuj yog cov iterators. A lub tshuab hluav taws xob zoo ib yam li a muaj nuj nqi uas rov qab ib array, nyob rau hauv uas a lub tshuab hluav taws xob muaj parameters, hu tau, thiab generates ib theem ntawm qhov tseem ceeb.

Ib sab saum toj no, dab tsi yog lub tshuab hluav taws xob khoom? Yooj yim hais, a lub tshuab hluav taws xob yog ib txoj haujlwm uas rov qab ib qho khoom (iterator) uas peb tuaj yeem iterate dua (ib tus nqi ntawm ib lub sijhawm).

Yog li ntawd, Python generator ua haujlwm li cas?

A Python generator yog ib qho kev ua haujlwm uas ua rau ib ntu ntawm cov txiaj ntsig. Nws ua haujlwm los ntawm kev tswj hwm nws lub xeev hauv zos, kom lub luag haujlwm tuaj yeem rov pib dua raws nraim qhov nws tau tso tseg thaum hu rau lub sijhawm tom ntej. Yog li, koj tuaj yeem xav txog a lub tshuab hluav taws xob raws li ib yam dab tsi zoo li ib tug haib iterator.

Koj hu lub tshuab hluav taws xob hauv Python li cas?

Thaum koj hu a lub tshuab hluav taws xob muaj nuj nqi los yog siv a lub tshuab hluav taws xob kev nthuav qhia, koj rov qab ib qho tshwj xeeb iterator hu ua a lub tshuab hluav taws xob . Koj tuaj yeem muab qhov no lub tshuab hluav taws xob mus rau qhov sib txawv kom siv tau. Thaum koj hu txoj kev tshwj xeeb ntawm lub tshuab hluav taws xob , xws li tom ntej (), cov cai hauv kev ua haujlwm tau ua tiav mus txog qhov txiaj ntsig.

Pom zoo: