3. What are Collections in Python?
• Collections in Python are like containers used for
storing data and are commonly known as data
structures, such as lists, tuples, set, dictionaries,
etc.
• Python has a built-in collections module providing
additional data structures for collections of data.
• The Python collection was first introduced in the
Python 2.4 version.
4. List
• List is a collection of data, where we can represent a
group of values as a single entity.
• We separate the items with commas(,) and keep all
the items of the entire list in square brackets[ ].
• In list data type insertion order is preserved.
• Duplicate values are allowed.
• Heterogeneous objects are allowed.
• List data type is mutable.
• Append method is applicable.
• It is possible to use index elements.
• Slice operation is also applicable.
5. Tuple
• It is same as list data type, but tuple is immutable.
• Once a tuple is created, no changes can be made to it.
• In this, instead of square brackets[ ], parenthesis( ) is used .
• Index and slicing are allowed.
6. Set
• Set is an unordered collection of items (insertion order
is not preserved).
• In set each element is unique, there is no duplicate
element.
• Set elements can be represent within curly braces{ }.
• Set is mutable, we can use add and remove methods.
• Heterogeneous objects are allowed.
• Index and slice operators are not applicable.