Python Forum

Full Version: How to return multiple values from function in python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
def abc(x, y):
    print x
    print y
    x = x + 1
    y = y + 1

x = 0
y = 1
x, y = abc(x,y)
When I execute this error, I got this error: TypeError: 'NoneType' object is not iterable.

What is the reason for this? Huh
Your function does not modify the global x and y.

You need to return the values.
def abc(x, y):
    x += 1
    y += 1
    return x, y
 
x = 0
y = 1
print("Before: {} {}".format(x, y))
x, y = abc(x,y)
print("After: {} {}".format(x, y))
Thank you Smile