Amjad Syed
Amjad Syed

Reputation: 195

store looped data in separate variables in python?

i want to store looped data from a returned function into separate variables. here is my code Please correct me if wrong

function:

 def rawi():
        a = raw_input("enter value of a")
        b = raw_input("enter value of b")
        return a, b

 #calling the above function:

 c = rawi()


 for i in c:
     print i

my desired output should be like : variable1 should have the value returned from a variable2 should have the value returned from b

thank

Upvotes: 0

Views: 77

Answers (2)

kren470
kren470

Reputation: 345

Your function should look like this if you'll loop through c:

def rawi():
    a = raw_input("enter value of a")
    b = raw_input("enter value of b")
    return (a, b) #you can return tuple/list/whatever that stores multiple variables

Upvotes: -1

mgilson
mgilson

Reputation: 309841

do you mean something like the following?

variable1, variable2 = rawi()

Upvotes: 5

Related Questions