OneBite.Dev - Coding blog in a bite size

declare a simple function in python

Code snippet on how to declare a simple function in python

def helloWorld():
  print("Hello World")

This code declares a simple function called ‘helloWorld’. The function will print out the string “Hello World”. The ‘def’ keyword is used in Python to declare a function. The parentheses are used to define the parameters that can be passed into the function if needed. In this case, we do not need to pass any parameters so the parentheses are left empty. Once the function is declared, all that’s left is to print the string “Hello World”. This is done with the print() function. The string is wrapped in quotation marks so Python knows it is a string. The function is complete, and when called will print out “Hello World”.

python