924 B
924 B
title | tags | aliases | ||||||
---|---|---|---|---|---|---|---|---|
functions |
|
|
[!note] Function Basics
A function in Python is defined using thedef
keyword, followed by a name, parameters in parentheses, and a colon. The body of the function must be indented.[!example] Defining and Calling Functions
def add(a, b): return a + b print(add(3, 4)) # 7
[!important] Indentation Matters
Python uses significant indentation. Inconsistent spacing will raise anIndentationError
.[!example] Printing vs Returning
def add_two_nums(num_one, num_two): total = num_one + num_two print(total) add_two_nums(32512, 325235623) # 325268135
[!info] Related Notes
expressions
docstrings
pythonSyntaxOverview