Lists and Tuples store one or more objects or values in a specific order.
The objects stored in a list or tuple can be of any type including the nothing type defined by the None Keyword.
The main difference between lists and a tuples is the fact that lists are
mutable whereas tuples are
immutable.
Syntax Differences
Lists are surrounded by square brackets [] and Tuples are surrounded by parenthesis ().
a= [1,2,3,4]
b= (1,2,3,4)
Mutable List vs Immutable Tuples
List has mutable nature i.e., we can be changed or modified after its creation according to needs whereas tuple has immutable nature i.e., tuple can’t be changed or modified after its creation.
Remeber
- The literal syntax of tuples is shown by parentheses () whereas the literal syntax of lists is shown by square brackets [] .
- Lists has variable length, tuple has fixed length.
- List has mutable nature, tuple has immutable nature.
- List has more functionality than the tuple.
Python dictionary is an unordered collection of items. While other compound data types have only value as an element, a dictionary has a key: value pair.
Dictionaries are optimized to retrieve values when the key is known.
How to create a dictionary?
Creating a dictionary is as simple as placing items inside curly braces {} separated by comma.
An item has a key and the corresponding value expressed as a pair, key: value.
There are mutable and Immutable types of Pythons built in types
Mutable built-in types
- List
- Sets
- Dictionaries
Immutable built-in types
- Strings
- Tuples
- Numbers
A tuple is a collection type data structure in Python which is immutable.
They are similar to sequences, just like the lists. However, There are some differences between a tuple and list; the former doesn’t allow modifications whereas the list does.
Also, the tuples use parentheses for enclosing, but the lists have square brackets in their syntax.