Whats "spam" meaning here? it doesnt have anything to do with neither eggs nor 12 no?

def spam():
  eggs = 12
  return eggs
print spam()


spam is the name of the function. maybe not in the exercise, but we could name the function get_eggs, which might make a little more sense:

// defining function
def get_eggs():
    eggs = 12
    return eggs

// calling function
print get_eggs()

functions are just a set of instructions we want to execute later. Then when we call the function (see comment in code block above), the function executes

its sort of like a task list, we can write the tasks which needs doing (function) and then execute it later (function call)

don’t worry if this doesn’t make complete sense yet, more on function will come


Thanks for your fast reply.


get_eggs/spam is just the name of function, or task/todo list in my analogy.

normally, i don’t name my task/todo lists, but in programming, we can have multiple or even many functions. imagine you have many task/todo lists, then naming them might make sense

Do you understand at least a little bit or any questions for now?


So its more like a title for every…task?
BTW, is the def function necessary?


doesn’t have to be. A function can be executed multiple times, so it can also be really good for repetitive tasks. And it can be used to structure your code.

once you will work more with functions, you will see there value


Thanks for your help :smile:


this lesson teaches the function concept, which at this moment doesn’t add much value, so i see your point/problem, just trust me, it will become clearer in the future :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.