For ... In | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

For ... In

I learn the lesson on that function, I understand the general concept but when I fall on a For ... In code portion, I have a lot of difficulties for read it. Maybe I think and I read the For ... In the wrong way, I don't know. How do you read this For... In ? Do you have an image way for reading it ? Thanks for your return guys !

13th Aug 2020, 6:17 PM
Greg GS
Greg GS - avatar
2 Answers
+ 4
A for loop in Python works on a container type: A list, dict, set, range, string or really anything else with multiple elements that can be iterated over. Let me give a few examples with pseudo code that may give you some intuition of how to read it: for book in bookshelf: read(book) (This means: Take every book from the bookshelf one by one and read them.) for task in textbook: do(task) for word in vocabulary: repeat(word) If you want to read more about the specifics (beyond the basics), look here: https://code.sololearn.com/cSdiWZr4Cdp7/?ref=app
13th Aug 2020, 6:32 PM
HonFu
HonFu - avatar
0
So in bookshelf, who is a list, a tuple or others, there is a list of title's book. With your code on For loop, I understand that I can chose any name (Maybe it is that part that was my understanding problem !). but the read do what on the code ? I understand the print who print all the book but the read ? ... Thanks for your help HonFu !
13th Aug 2020, 6:54 PM
Greg GS
Greg GS - avatar