Lesson 6/13 What does def spam() means at the beginning of the code, and how it is used for printing
def keyword is how we define a function. A function is a code segment (a block) that we can call up any time and have that piece of code execute.
def foo(): print ("Foo!") foo() # Foo!
The top line is called the header or signature line. That tells Python what name to store the function with, and what parameters are expected by the function. In the above there are no expected parameters. Notice that the last line, which is is the function call expression statement uses empty parens to indicate no arguments (to match the no expected parameters).
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.