Tuples’ immutability resembles a vault - safe and untouchable. Tuples are safer than lists if the stored data isn’t meant to change since tuples are immutable while lists are mutable.Tuple operations are faster than similar list operations - see this stackoverflow post for more info.Tuples are fixed in size due to immutability - we cannot add or remove any elements to a tuple.Here are further points to note about tuples: The main difference between tuples and lists is that tuples are immutable - meaning that the data stored in a tuple cannot be modified after the tuple has been created. Tuple data type is pretty similar to list in that tuples allow individual items to be of different data types. The data values stored within a list are separated by commas. Just like how we recognise strings by their enclosing quotes, we can recognise lists by enclosing square brackets. This means that a list can contain integers, strings or even other lists. List data type is pretty similar to string data type except that lists are more general - they allow individual items to be of different data types. Like strings, these data types store data values one after another and allow for operations such as looking up stored items to be performed on a sequence. There are other sequential data types in Python like tuples and lists. Introducing the Sequential Data TypeĪs we have seen above, String is a Sequential Data Type because of the way it stores characters in sequence. Strings are sequences of characters - and each character of a string is stored as a data value itself.įurthermore, the characters of a string are stored in sequence - which means that there is an order to the way each character is stored and that each character has a position - like in “abc”, the character “a” is in position 0, “b” is in position 1 while “c” is in position 2. Some data types in Python are made up of a collection of data values - like lists and strings.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |