Functions
Learn about code reuse with Python functions. Apply that knowledge to create functions for famous physics formulas.
StartKey Concepts
Review core concepts you need to learn to master this subject
Returning Multiple Values
The Scope of Variables
Function Parameters
Multiple Parameters
Returning Value from Function
Functions
Function Indentation
Calling Functions
Returning Multiple Values
Returning Multiple Values
def square_point(x, y, z):
x_squared = x * x
y_squared = y * y
z_squared = z * z
# Return all three values:
return x_squared, y_squared, z_squared
three_squared, four_squared, five_squared = square_point(3, 4, 5)
Python functions are able to return multiple values using one return
statement. All values that should be returned are listed after the return
keyword and are separated by commas.
In the example, the function square_point()
returns x_squared
, y_squared
, and z_squared
.
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory