I've recently learned how to use "def" in Python and was messing about with it but then encountered an issue:
after assigning values to a variable within a function I'm defining, when trying to do something with that variable outside of the function, it seems like nothing was ever assigned to that variable? I'm not really sure.
def sum(x, y):
test = x + y
sum(1, 2)
print(test)
When running this code, I expect the output to be 3 but it tells me that "test" is not defined.However I get my desired output when it's formatted this way:
def sum(x, y):
res = x + y
print(res)
sum(1, 2)