Nyob hauv khoom tsis yog iterable?

Cov txheej txheem:

Nyob hauv khoom tsis yog iterable?
Nyob hauv khoom tsis yog iterable?
Anonim

TypeErrors yog ib hom kev ua yuam kev hauv Python. Lawv tshwm sim thaum koj sim siv lub luag haujlwm ntawm tus nqi ntawm hom tsis raug. Qhov "'int' object is not iterable" yuam kev yog tsa thaum koj sim iterate dua tus nqi suav. Txhawm rau daws qhov yuam kev no, xyuas kom tseeb tias koj tab tom rov ua dua ib qho uas tsis yog tus lej.

Vim li cas kuv qhov khoom tsis tuaj yeem hais tau?

Nyob rau hauv JavaScript, Object s tsis yog iterable tshwj tsis yog lawv siv cov txheej txheem iterable. Yog li ntawd, koj tsis tuaj yeem siv rau … ntawm iterate tshaj cov khoom ntawm ib yam khoom. … cov yuam sij lossis Object. nkag, kom rov hais dua cov khoom lossis nkag ntawm ib qho khoom.

Kuv yuav ua li cas thiaj li ua tau zoo hauv Python?

Iterables hauv Python yog cov khoom thiab ntim khoom uas tuaj yeem hla dhau ib yam khoom ntawm ib lub sijhawm, feem ntau siv ib qho rau … hauv voj. Tsis yog txhua yam khoom tuaj yeem rov ua dua, piv txwv li - peb tsis tuaj yeem ntsuas tus lej, nws yog tus nqi sib npaug.

Lub ntsiab lus ntawm iterable yog dab tsi?

Definition: Ib qho iterable yog ib yam khoom Python muaj peev xwm xa rov qab nws cov tswv cuab ib zaug, tso cai rau nws rov ua dua nyob rau hauv ib lub voj. Cov piv txwv paub ntawm iterables muaj xws li cov npe, tuples, thiab cov hlua - ib qho kab ke no tuaj yeem rov ua dua hauv ib lub voj voog.

Txoj hlua tsis tuaj yeem ua tau?

Ib txoj hlua yog qhov hloov tsis tau ntawm cov bytes. Cov hlua yog iterable; iteration tshaj ib txoj hlua yields txhua ntawm nws 1-byte substrings nyob rau hauv kev txiav txim. Tab sis String tsissiv Iterable's Iterate method. … String tuaj yeem siv Iterable, hauv kev xav, los ntawm kev xa rov qab ib qho iterator uas hla txhua ib-byte substring mus rau Tom ntej.

Pom zoo: