#########################
def func(x):
    """Evaluate a function"""
    return x**2 - np.sin(x)
#########################

Every function definition begins with the words def followed by what you want to name the function in this case it is func. After the name of the function you need to add enclosed parentheses () and finally a colon : . Inside the parentheses your argument list can have:
  • no argument
  • one argument
  • as many arguments as you like/need.

    The definition of the function is at the top of your script because python requires they are defined before they get used.
    The general pattern for definition is
    def function-name(function-argument-list):
       """Comment"""
       function-statements
    
    
    The comment inside the function is optional. Standard Python style puts the comment line immediately after the def line. (With three quotes)

    Finally the result of the function is handed back as what is after the return value.
    Note that defining a function inside main is discouraged.
  • limits usability. It can not be used outside the main function
  • Introduces bugs. It will let you overwrite a function with the same name elsewhere.