You are on page 1of 3

Answer No 01:

Python collections types:


Collections in Python are containers that are used to store collections of data. These are built-
in collections. When choosing a collection type, it is useful to understand the properties of that
type. Choosing the right type for a particular data set could mean retention of meaning, and, it
could mean an increase in efficiency or security.

There are four collection data types in the Python programming language:

1. List
2. Tuple
3. Set
4. Dictionary

List:
List is a collection which is ordered, mutable and changeable. It allows duplicate members. Each
element or value that is inside of a list is called an “item”.

Example:

list = [“apple”, “banana”, “cherry”]

print(list)

Output:

[‘apple’, ‘banana’, ‘cherry’]

Tuple:
Tuple is a collection which is ordered and unchangeable. It also allows duplicate members.
In Python tuples are written with round brackets. Tuples are used to group together related data,
such as a person's name, their age, and their gender.

Example:

tuple = (“apple”, “banana”, “cherry”)


print(tuple)

Output:

(‘apple’, ‘banana’, ‘cherry’)

Set:
Set is a collection which is unordered and unindexed. It does not allow duplicate members.
In Python sets are written with curly brackets.

Example:

thisset = {“apple”, “banana”, “cherry”}

print(thisset)

Output:

{‘apple’, ‘banana’, ‘cherry’}

Dictionary:
Dictionary is a collection which is unordered, changeable and indexed. It also not allow duplicate
members. In Python, dictionaries are written with curly brackets, and they have keys and values.

Example:

thisdict = {

“brand” : “Apple”,

“model” : “hot9”,

“year” : 2020

print(thisdict)

Output:
{‘brand’ : ‘Apple’, ‘model’: ‘hot9’, ‘year’: 2020}

You might also like