The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

Difference between Tuples and Lists

Difference between Tuples and Lists

0
Votes
1
Answer

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 Answer

365 Team
0
Votes

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