last day (16 days later) » 

08:16
hello @JohnRennie sir
Hi :-)
can you explain for loops
Can you say what about them you are having difficulty with? So I know where to start.
the begning of it is not explained in proper way
he starts out by saying
to print items of a list
use for item in list:
print(item)
but how does this code work
In Python many objects are iterable. This sounds complicated but it just means the objects are made up from several components and you can step through the components one by one. OK so far?
08:22
ok
For example a list is iterable because it contains elements l[0], l[1], etc and you can step though the elements in the list using an integer 𝑖 where 𝑖 goes from 0 up to the length of the list.
And in Python for loop is a way of iterating through any iterable object. For example the code:
for i in mylist:
    print(i)
will step through every element in mylist setting the variable i to each element of the list in turn.
So this will print each element of the list.
Does this make sense so far?
if it is a loop
how does it know everytime
to set i to next element
in every other cycle
The for loop keeps track of which element it is looking at, so once it has done that element it knows what the next element is. All this is done for you by the Python interpreter so you don't need to know exactly how it is done.
If you are curious I can point you to web pages explaining exactly how it works, but i wouldn't worry about for now.
08:30
ok
@JohnRennie ok
That's pretty much all you need to know about for loops. They will step through any iterable object.

  last day (16 days later) »