0% found this document useful (0 votes)
34 views3 pages

Answer No 01

There are four main collection data types in Python: lists, tuples, sets, and dictionaries. Lists are ordered and mutable collections that allow duplicate elements. Tuples are ordered and immutable collections that allow duplicate elements. Sets are unordered and unindexed collections that do not allow duplicate elements. Dictionaries are unordered, changeable collections that are indexed and composed of keys and values, not allowing duplicate keys.

Uploaded by

Ayesha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views3 pages

Answer No 01

There are four main collection data types in Python: lists, tuples, sets, and dictionaries. Lists are ordered and mutable collections that allow duplicate elements. Tuples are ordered and immutable collections that allow duplicate elements. Sets are unordered and unindexed collections that do not allow duplicate elements. Dictionaries are unordered, changeable collections that are indexed and composed of keys and values, not allowing duplicate keys.

Uploaded by

Ayesha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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