Lesson 3 of 19 · 2 min
Defining and Calling a Function
# DEFINING a function — writing the recipe card
def greet(): # 'def' keyword | function name | () | colon
print("Hello!") # body starts here — indented 4 spaces
print("Welcome to Python!") # every indented line belongs to the function
# CALLING a function — using the recipe
greet() # call it once → both print statements run
greet() # call it again → exact same output, no rewriting needed
Output: Hello! Welcome to Python! Hello! Welcome to Python!
Keyword-by-keyword breakdown:
def— keyword that tells Python "a function definition begins here"- function name — snake_case convention (e.g.
calculate_tax,send_email) ()— parentheses required even when empty:— colon is mandatory at the end of the def line- body — all lines indented 4 spaces; runs every time the function is called
