← Courses

Python for AI — Beginner Foundations

Data Science

Functions · Lesson 41 of 76

Parameters

Parameters are the inputs a function accepts — the values you put in the brackets when you call it.

Python

You can give a parameter a default value, used when the caller doesn't supply one:

Python

Your turn: write power(base, exponent=2) that returns base ** exponent, and print power(5) and power(2, 3).

Check your understanding

Exercise — check your understanding

Write greet(name, greeting="Hello") that returns the greeting, a comma and space, the name, then !. Example: greet("Ada") gives "Hello, Ada!".

You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →