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

Quiz

Uploaded by

I KB
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)
23 views3 pages

Quiz

Uploaded by

I KB
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

COMSATS UNIVERSITY, WAH CAMPUS

DEPARTMENT OF COMPUTER SCIENCE

Introduction to ICT

Assignment and Quiz

Name: Ayesha Amjad


Registration no.: FA20-BSE-105
Section: C-1
Submitted to: Sir Muhammad Arslan
Dated: 20/12/2020
Answer
Lists:
Lists are just like dynamic sized arrays. Lists need not be homogeneous always which
makes it the most powerful tool in Python. The main characteristics of lists are:
 The list is a data type available in Python which can be written as a list of comma-
separated values (items) between square brackets.
 List are mutable i.e. it can be converted into another data type and can store any data
element in it.
 List can store any type of element.

Tuple:
Tuple is a collection of Python objects much like a list. The sequence of values stored in
a tuple can be of any type, and they are indexed by integers. Values of a tuple are
syntactically separated by ‘commas’. Although it is not necessary, it is more common to
define a tuple by closing the sequence of values in parentheses. The main characteristics
of tuples are:
 Tuple is an immutable sequence in python.
 It cannot be changed or replaced since it is immutable.
 It is defined under parenthesis ().
 Tuples can store any type of element.

Set:
Set is an unordered collection of data type that is iterable, mutable, and has no duplicate
elements. The major advantage of using a set, as opposed to a list, is that it has a highly
optimized method for checking whether a specific element is contained in the set. The
main characteristics of set are:
 Sets are an unordered collection of elements or unintended collection of items. In
python.
 Here the order in which the elements are added into the set is not fixed, it can
change frequently.
 It is defined under curly braces {}.
 Sets are mutable, however, only immutable objects can be stored in it.

Dictionary:
Dictionary is an unordered collection of data values, used to store data values like a
map, which unlike other Data Types that hold only single value as an element,
Dictionary holds key: value pair. Key value is provided in the dictionary to make it
more optimized. The main characteristics of dictionary are:
 Dictionary can be created by placing sequence of elements within curly {} braces,
separated by ‘comma’.
 Dictionary holds a pair of values, one being the Key and the other corresponding
pair element being its key: value.
 Values in a dictionary can be of any data type.
 Values can be duplicated whereas keys can’t be repeated must be immutable.

List Set Tuple Dictionary


It is Mutable It is Mutable It is Immutable It is Immutable
It is ordered collection of It is Unordered It is ordered collection It is unordered
items. collection of items. of items. collection of items.

Items in list can be Items in set cannot be Items in tuple cannot be Item in dictionary can
replaced or changed replaced or changed replaced or changed be replaced or changed.

Items in list are bounded Items in set are bounded Items in tuple are Items in dictionary are
by square brackets [] by curly brackets {} bounded by round bounded by curly
brackets () brackets {}

Example Example Example Example


my_list = ["My", "age", set1 = set(['My', tuple1 = (1, 'Ayesha', 2, my_self =
"is", 19] 'username', 'is', 12345]) 'Amjad') {1:'Ayesha',2:'Software
print(my_list) print(set1) print(tuple1) Engineer'}
print(my_self[1])
Output: Output: Output: print(my_self[2])
['My', 'age', 'is', 19] {12345, 'is', 'username', (1, 'Ayesha', 2, 'Amjad')
'My'} Output:
Ayesha
Software Engineer

You might also like