Difference between Tuples and Lists
In the intro to Python Course, there is a section on Tuples. At minute 1:35 of the video, it states there are a few key differences between lists and tuples worth nothing. Immediately it jumps into how Tuples can be split, and how functions can return tuples. Is this something that lists cannot do?
1 answers ( 0 marked as helpful)
Hi Daniel!
Thanks for reaching out.
We say there are some subtle differences. What we meant was just that in certain scripts (oftentimes - more advanced scripts, or just scripts related to other fields - e.g. we don't really need to exploit this difference within this part of the program) this difference can matter.
In any case, many methods or functions will return tuples by default. Tuples are also very convenient to process for further computations.
Yes, you can do that with lists, but you'd need to do it specifically and have a particular reason to request lists as opposed to tuples.
Here's an example.
def square_info(x):
A = x ** 2
P = 4 * x
print ("Area and Perimeter:")
return [A,P] square_info(2) Hope this helps.
Best,
Martin
A = x ** 2
P = 4 * x
print ("Area and Perimeter:")
return [A,P] square_info(2) Hope this helps.
Best,
Martin