How To Define A Function In Python?

Use the `def` keyword

Write the function name

Add parentheses `()`

Include parameters inside the parentheses if needed

End the function header with a colon `:`

Indent the function body

Use `return` to send a value back if needed

Call the function using its name followed by parentheses

Example: `def my_function():`

Example: `def add(a, b):`

Example: `return a + b`

Suggested for You

Trending Today