python iterate code example
Example 1: python loop through list
list = [1, 3, 6, 9, 12]
for i in list:
print(i)
Example 2: loop through python object
for attr, value in k.__dict__.items():
print(attr, value)
Example 3: what is iteration in python
# Iteration is the execution of a statement repeatedly and without
# making any errors.
Example 4: how to use iteration in python
>>> a = ['foo', 'bar', 'baz']
>>> for i in a:
... print(i)
...
foo
bar
baz
Example 5: iterate through objects with python
class C:
a = 5
b = [1,2,3]
def foobar():
b = "hi"
for attr, value in C.__dict__.iteritems():
print "Attribute: " + str(attr or "")
print "Value: " + str(value or "")
Example 6: how to use iteration in python
for i = 1 to 10
<loop body>