Python 3

Function with One Parameter in Python

In Python, we can define functions to make our code reusable, more readable, and organized. This is the basic syntax of a Python function:

Tip: a function can have zero, one, or multiple parameters.

A function with one or more parameters has a list of parameters surrounded by parentheses after its name in the function definition:

When we call the function, we just need to pass one value as argument and that value will be replaced where we use the parameter in the function definition:

Here we have another example – a function that prints a pattern made with asterisks. You have to specify how many rows you want to print:

You can see the different outputs for different values of num_rows:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.