capypad
0 day streak
python / beginner
Snippet

Defining a Function

Functions allow you to wrap a block of code and reuse it throughout your program by calling its name.

snippet.py
python
1
2
3
4
def greet(user_name):
return f'Welcome, {user_name}!'
 
message = greet('Charlie')
Breakdown
1
def greet(user_name):
Defines a new function named 'greet' that accepts one parameter.
2
return f'Welcome...'
Sends a value back to the caller of the function.