def function_name():
print("Hello this is a function")
#To call the above function use
function_name()
You can create a function in python by using the 'def' keyword before the function name. The above code snippet function will print - Hello this is a function when called. You can also use the function to return some values or data when called.
You can also pass parameters to a function and use them inside the function code block.
Passing parameters to function
The code will output 'Hello John' as we called the function by passing 'John' as 'username' parameter value.