I would like a bit of clarification here


#1

def spam():
"""This will print 'Eggs!'"""
print "Eggs!"
spam()

Why do I have to end the code with "spam()"? What does that do and why will "Eggs!" not print without it?


#2

When you write the code

def spam()
    print "Eggs!"

your just making a function. In this case, the functions name is spam() and all that it does is print "Eggs!" A function is just a chunk of code that can be called, but it won't just run by itself. In order to call your function and make it print "Eggs!" you write

spam()

This basically just finds the function called spam and does whatever it is that you programmed it do, in this case, it will print "Eggs!"

Let me know if you have any questions :smiley:


#3

That makes sense, thank you!


#4

No problem! Could you click the button on my answer that says something like "solution" or "accept answer" to show that the question has been answered? Thanks!