Home / Python Tutorial / Day 9
Day 9 — Python functions with def
A function is a named piece of work you can reuse. The moment you copy and paste code, you wanted a function.
Defining and calling
Arguments
return — handing a value back
print and return are not the same
print shows something to a human. return hands a value back to your code so you can use it further. A function that prints but does not return gives you None if you try to store it.Several arguments
Default values
A function that makes a decision
Functions calling functions
Try these yourself
- Write a function that returns the square of a number.
- Write average(numbers) that takes a list and returns the mean.
- Write a function with a default discount of 10%.
- Write is_even(n) that returns True or False.
Ready for pandas and real projects?
This tutorial covers core Python. Our Data Analytics course takes you into pandas, NumPy, real files and visualisation, with mentor support and portfolio projects.
See the course →