Hoo-whee, we are really getting into it now, aren’t we! I know this blog is only a week old, but I’ve been working on Learn Python the Hard Way for just shy of two months, and that I’ve gotten through 19 lessons is quite exciting for me! Getting somewhere, even if I am not being assessed – now THERE’S adulthood! Well, maybe it’d be more adult if it wasn’t just so fun!
def cheese_and_crackers(cheese_count, boxes_of_crackers):
print "You have %d cheeses!" % cheese_count
print "You have %d boxes of crackers!" % boxes_of_crackers
We start out by defining
cheese_and_crackers, a function that prints out a few statements with the given variables. Just a skosh down the road, we start putting values in for
boxes_of_crackers, but suddenly! ack!
amount_of_cheese = 10
amount_of_crackers = 50
Now we’re calling
cheese_count by the name of
amount_of_cheese! WELL. The neat thing here is that in defining the function, we’ve named it something convenient for ourselves, but when we refer to it later, the var should be called something else, to distinguish from the name/s given in the initially defined function. Follow me here:
def function(thing_a, thing_b)
print "here's the %s things and the %s other things" % (thing_a, thing_b)
number_of_things_boop = 20
number_of_things_doop = 30
So that last bit calls the function itself, to which the variables ..
_boop and ..
_doop are passed, and since the function initially requires two variables, any two passed in there will then be given the roles of
thing_b given in the function. Hoo! I have read this paragraph aloud to myself several times, and I think that it makes sense?
So that’s Lesson 19, and it’s also the lesson in which I learned about the html code tag! The explanation is much lengthier than my understanding would have given, but I’m really pleased to have ironed it out so thoroughly, at least for myself. Crystal clear, now!