I am watching Introduction to Computer Science and Programming in Python of MIT Open Course Ware. In Lecture 5 which introduces Tuples, the Professor says that you are only allowed to return one object in functions
. And then she says, tuples are handy for returning more than one object values.(For anyone who want to watch this short part of the lecture which starts at 06:15 min). The question is regarding the MIT Lecture:
Yes, we can use Tuples for returning and collecting a couple of values. On the other hand, a function in Python already can return more than one value by separating them by commas. As a result, I am confused with what the lecturer said. Is returning 2 or more values by separating with commas mean that these objects are becoming an item of a tuple although it is not declared explicitly? What am I missing? In other words, what is the difference between separating with comma as x,y
and in parenthesis as (x,y)
. You can provide explanation by using the function below. Thanks.
def smth(x,y):
x = y % 2
y = x % 5
return x, y