user24736
0
Q:

python return multiple values

# A Python program to return multiple  
# values from a method using tuple 
  
# This function returns a tuple 
def fun(): 
    str = "geeksforgeeks"
    x   = 20
    return str, x;  # Return tuple, we could also 
                    # write (str, x) 
  
# Driver code to test above method 
str, x = fun() # Assign returned tuple 
print(str) 
print(x) 
2
return a, b
1
def fun(): 
    str = "geeksforgeeks"
    x   = 20
    return str, x
11
# A Python program to return multiple  
# values from a method using class 
class Test: 
    def __init__(self): 
        self.str = "geeksforgeeks"
        self.x = 20   
  
# This function returns an object of Test 
def fun(): 
    return Test() 
      
# Driver code to test above method 
t = fun()  
print(t.str) 
print(t.x) 
1

New to Communities?

Join the community