OneBite.Dev - Coding blog in a bite size

declare a function with single parameter in python

Code snippet on how to declare a function with single parameter in python

def my_function(parameter1):
  # Add your code here

This code defines a function called ‘my_function’ which takes a single parameter called ‘parameter1’. The function is declared using the ‘def’ keyword, followed by the name of the function and then the parameter within parentheses. The code is then concluded with the ’:’ character followed by an indented block containing the instructions to be executed. Currently, the function is empty and waiting to be filled with instructions. Once completed, the function can be called, passing the appropriate data to the parameter, and the instructions will be executed.

python