Hello, I am working on a code in python with def variable():
and I was wondering if I need to have a return function at the end even if it does not have a parameter and runs fine without it?
what is the purpose of your function? Is it to output something or do you want to get something from it? If you want to get something from it, its best to use return. However, if you only want output, then dont return anything. For example,
def add(x, y): # im not sure if u need to assign types to arguments/parameteres in python return x + y print(add(1, 1)) # -> 2
however, you can do something like
def add_and_print(x, y): print((x + y)) add_and_print(1, 1) # -> 2