Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to return multiple values from function in python
#1
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
Quote
#2
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))
Quote
#3
Thank you Smile
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Reading Multiple Lists Using SUM function dgrunwal 6 246 Jun-03-2020, 08:23 PM
Last Post: dgrunwal
  How to pass multiple values from one sample to nc variable? Baloch 0 95 Jun-01-2020, 09:27 PM
Last Post: Baloch
  return string from function with one argument jamie_01 2 112 May-28-2020, 11:07 PM
Last Post: menator01
  Inserting values from multiple lists sqlite azulu 1 256 May-24-2020, 08:40 AM
Last Post: ibreeden
  Return Multiple or one just JohnnyCoffee 14 533 May-01-2020, 11:26 AM
Last Post: JohnnyCoffee
  UnUnloading values from multiple widgets in a container UGuntupalli 3 248 Apr-20-2020, 08:53 PM
Last Post: UGuntupalli
  What is the best way to return these 4 integer values? Pedroski55 4 231 Apr-13-2020, 09:54 PM
Last Post: Pedroski55
  Return values for use outside of function willowman 1 142 Apr-13-2020, 07:00 AM
Last Post: buran
  Return all Values which can divided by 9 lastyle 2 214 Mar-16-2020, 09:22 PM
Last Post: lastyle
  Function with many arguments, with some default values medatib531 3 267 Mar-14-2020, 02:39 AM
Last Post: medatib531

Forum Jump:


Users browsing this thread: 1 Guest(s)