Quote:
|
Originally Posted by zem52887
is this kind of what it's supposed to look like?
|
Nearly. Your problem is your unfamiliarity functions and lists.
Think of a function as a mysterious machine. You put items into this machine, and get out other items. For instance, say you had a machine that painted everything red; it doesn't matter what you put into the machine, it'll always come out red.
In Python, this red-painting machine might look like this:
def paint_red(item):
item.colour = "red"
And you might use this function like so:
# Create a cat called Percy
cat = Cat("Percy")
# Create a table
table = Table()
# Create a chair
chair = Chair()
paint_red(cat)
paint_red(table)
paint_red(chair) Notice that it doesn't matter what goes into the function, it all gets treated the same.
Another key point is the concept of references. The name of an object is independant from what it is. Or, to put it another way, a rose by any other name would still smell as sweet. If you called a chair a "foobar", then it would still have four legs and a back. Changing the name of something doesn't change what it is.
So, take the following code:
cat = Cat("Percy")
item = cat This code tells Python that Percy the Cat is referenced by the "cat" variable. The "cat" variable is something that points to Percy, like a signpost. The "item" variable also points to Percy. You can call Percy a cat, or you can call him an item; it's still the same cat.
Is that a little more understandable?