def my_function_name():
  #Function code

//Calling it

Using Parameters

def my_function_name(my_variable1, my_variable2):
  #Function code

//Calling it
my_function_name(21, "abc")

my_function_name(my_variable1=21, my_variable2="abc")
my_function_name(my_variable2="abc", my_variable1=21)
Default values
def my_function_name(my_variable1, my_variable2="abc"):
  #Function code

//Calling it
my_function_name(21, "def")

Return values

def my_function_name():
  return 21

//Calling it
return_value = my_function_name()
Multiple return values
def my_function_name():
  return 21, "abc", 55

//Calling it
return_value_1, return_value_2, return_value_3 = my_function_name()
Using a dictionary for multiple return values
#In the function:
    if something == True:
        return_values = {}
        return_values['Something1'] = "abc"
        return_values['Something2'] = "def"
        return_values['Something3'] = "ghi"
        return return_values

    return False

#Calling it
    return_value = my_function(camera_serial_number)
    if return_value != False:
        #### = return_value['Something2']

Calling a function before it is defined

Nope. You don’t do that in Python! All functions must be defined before they are used.

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.


Your email address will not be published. Required fields are marked *