How to return multiple values from a function in Python

3 Answers

0 votes
def strings_to_upper(str1, str2):
    return str1.upper(), str2.upper()


s1 = "python"
s2 = "java"

result = strings_to_upper(s1, s2)

print(result)

print(s1)
print(s2)

s1 = result[0]
s2 = result[1]

print(s1)
print(s2)


'''
run:

('PYTHON', 'JAVA')
python
java
PYTHON
JAVA

'''

 



answered Oct 29, 2018 by avibootz
0 votes
def f(): 
    return 81, 34, 65, 58
    
a, b, c, d = f() 
  
print(a, b, c, d) 



'''
run

81 34 65 58

'''

 



answered Apr 8, 2019 by avibootz
0 votes
def f(n):
    a = n * 2
    b = n * 3
    return a, b
 

result = f(12)
 
print(result)
 
x = result[0]
y = result[1]
 
print(x)
print(y)
 
 
 
 
'''
run:
 
(24, 36)
24
36
 
'''

 



answered Dec 17, 2021 by avibootz
...