Beginners guide to Iteration in python

The basics of dealing with many things in code.

Keno Leon

--

gaetanlee [CC BY (https://creativecommons.org/licenses/by/2.0)]

Writing software usually starts in your head, you think about something and then you want to take that something out of your imagination and write it into code and execute it as a program, many times, what’s in your head involves making and manipulating many things; I hope that by the end of this short tutorial you will be able to do just that, think in multiples of things and write those things in Python code.

We will be using a rubber duck as the thing we will be dealing with throughout this guide, as such here’s a simple Rubber duck module:

File: Rubber_Duck_Factory.py*You can also include this class at the top of your scripts instead of the import statements if you find that more convenient.class RubberDuck():
color = 'yellow'
USAGE:File: makeOne.pyimport Rubber_Duck_FactoryOneDucky = Rubber_Duck_Factory.RubberDuck()
print(OneDucky.color)
# yellow
* Not to be confused with the factory method pattern, that's related but advanced stuff not covered here.

--

--

Responses (1)