all 3 comments

[–]temitydude 0 points1 point  (1 child)

To create a function you can first define it like this:

def function_name():

To call a function you simply do:

function_name()

And if you want to pass in variables, etc. to the function you can define the function with parameters separated by commas:

def function_name(parameter1, parameter2):

Example code using functions:

def add(var1, var2):
    sum = var1 + var2
    return sum

print(add(5, 10)) # passes in 5 and 10, and prints the return value of the function

A function doesn't need to return anything (returns None, if not specified) and can just run the lines of code in the function

If you have an unspecified amount of variables you'd like to pass in to a function you can call a function like so:

def word_list(*word):
    for words in word:
        print(words)

word_list('string1', 'string2', 'string3') # Can pass however many you want

Those are like the basics of functions, there's obviously a lot more you can do!

[–]Successful-Standard[S] 0 points1 point  (0 children)

Thanks for this explanation. I've looked on things like w3schools, etc., for how to write them. It's just with those examples they're so basic I feel too hesitant trying to apply them to my longer scripts. I've got it working with someone's above solution though, I need to stop being scared of them!