python – AttributeError: tuple object has no attribute

python – AttributeError: tuple object has no attribute

You return four variables s1,s2,s3,s4 and receive them using a single variable obj. This is what is called a tuple, obj is associated with 4 values, the values of s1,s2,s3,s4. So, use index as you use in a list to get the value you want, in order.

obj=list_benefits()
print obj[0] +  is a benefit of functions!
print obj[1] +  is a benefit of functions!
print obj[2] +  is a benefit of functions!
print obj[3] +  is a benefit of functions!

Youre returning a tuple. Index it.

obj=list_benefits()
print obj[0] +  is a benefit of functions!
print obj[1] +  is a benefit of functions!
print obj[2] +  is a benefit of functions!

python – AttributeError: tuple object has no attribute

Variables names are only locally meaningful.

Once you hit

return s1,s2,s3,s4

at the end of the method, Python constructs a tuple with the values of s1, s2, s3 and s4 as its four members at index 0, 1, 2 and 3 – NOT a dictionary of variable names to values, NOT an object with variable names and their values, etc.

If you want the variable names to be meaningful after you hit return in the method, you must create an object or dictionary.

Leave a Reply

Your email address will not be published.