Okay, so up until now, I have this question bugging me. I can't seem to understand about the practical difference between tuples and lists. Like, do they have an underlying structural difference or not, when I should use a tuple, and when I should use a list instead, that is, if I only have 2 items to store.
So far the only difference that I have seen is , List are mutable and tuples are not..nothing more.. so in lists I can change or delete a particular element but in tuples I can't.. But I am just on lecture 7..so there may be more to it..
idk.
Well, at least that's news to me. Thanks guys.
this might help: http://stackoverflow.com/questions/626759/whats-the-difference-between-list-and-tuples-in-python
LoL he got a medal for an idk.??...man this world is really strange ... and yes the 'tuples are homogeneous and lists are heterogeneous ' thing was also in the lecture..:)
Nah, I'm just a kind person :)
lists have a few more methods. sometimes it is convenient to change a tuple to a list so you can use a list method to do something then turn it back into a tuple
I don't know how you add something to a tuple ( there may be a way, I just don't know it). on the other hand......list_name.append(thing you want to append).....
Well yeah, a tuple is immutable.... I suppose I gotta get that engraved in my mind.
The reason for the difference is that mutable objects are typically not hashable. As such, it's not reasonable to use a list as a key for a dict or store them in a set, but you can use a tuple for either.
Join our real-time social learning platform and learn together with your friends!