Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Python for the students, Schemes and Mind Maps of Programming Paradigms

Python in b com ca department year 2024vishal vm professor it is all about simple coding in python

Typology: Schemes and Mind Maps

2023/2024

Available from 12/19/2024

ramesh-raja-1
ramesh-raja-1 🇮🇳

1 document

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
(Affiliated to University of Madras)
PERI Knowledge Park, Mannivakkam, Chennai-600 048.
PG DEPARTMENT OF B COM CA & CS
Course Code and Name: 147E1B PYTHON Year & Sec: I B COM
CAUnit 5.1 Assignment and Test 5.1
Part A (2 mark Questions)
1
What is Dictionary?*
The unordered data structure stored as key and value pair, access by key value .It is built-in
type denoted by dict.
2
What is the use of disct() function?
The disct() is a constructor function used to construct Dictionary in Python. Example
is given below:
Dd = disct ()
3
How to access items in set?
Availability of items in set can be checked using member operator. The set is not subscript able
so the items are not accessible individually using index position.
4
What are the operations can be performed on set.
The set is provided with operations like, intersection, union, difference and symmetric.
5
What is frozenset() function?
The constructor frozenset() is used to create the immutable set. No modification or element
adding function can be used on frozen set. All the other operation like set operation and
comparison are allowed on frozen set.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Python for the students and more Schemes and Mind Maps Programming Paradigms in PDF only on Docsity!

(Affiliated to University of Madras)

PERI Knowledge Park, Mannivakkam, Chennai- 600 048. PG DEPARTMENT OF B COM CA & CS

Course Code and Name: 147E1B PYTHON Year & Sec: I B COM

CAUnit 5.1 Assignment and Test 5.

Part A (2 mark Questions)

1 What is Dictionary?*

The unordered data structure stored as key and value pair, access by key value .It is built-in type denoted by dict.

2 What is the use of disct() function?

The disct() is a constructor function used to construct Dictionary in Python. Example

is given below:

Dd = disct ()

3 How^ to access items in^ set?

Availability of items in set can be checked using member operator. The set is not subscript able so the items are not accessible individually using index position.

4 What^ are^ the^ operations^ can^ be^ performed^ on^ set.

The set is provided with operations like, intersection, union, difference and symmetric.

5 What is frozenset() function?

The constructor frozenset() is used to create the immutable set. No modification or element adding function can be used on frozen set. All the other operation like set operation and comparison are allowed on frozen set.

6 What is^ Set?

The Set is mutable (Changeable after creation) unordered data structure. It doesn’t allow duplicate values. It is denoted by ‘Set’. Items in Set are enclosed by curly braces {}.

7 Difference^ between^ set()^ and frozenset().

set() frozenset()

Set is mutable (Changeable after creation) used to create the immutable set by default Modification or element adding function can No Modification or element adding function be used can be used on frozen set Items in Set are enclosed by curly braces {} The frozen set element are printed with extra enclose parenthesis () preceded with keyword frozen.

8 What^ are^ the^ set^ operations?

  1. Union Operation
  2. Union Function
  3. Intersection Operation
  4. Intersection Function
  5. Difference Operations
  6. Difference Function
  7. Symmetric Difference Operations
  8. Symmetric Difference Function

9 What^ set^ iteration.

The loop statement is used to work on all the items in set sequentially. One item can be assigned to variable in each iteration of loop.

Part B (5 mark Questions)

1 Explain^ about^ comparison^ operator^ of^ Set.

Sets support various set operations like union, intersection, and difference. Union: set1 = {1, 2, 3} set2 = {3, 4, 5} union_set = set1.union(set2) Intersection: intersection_set = set1.intersection(set2) Difference: difference_set = set1.difference(set2) Iterating Over Sets: You can use a for loop to iterate over the elements in a set. for item in my_set: print(item) Set Comprehensions: Like list comprehensions, Python supports set comprehensions for creating sets in a concise manner. squares = {x * x for x in range(1, 6)}

2 Briefly^ explain^ Dictionaries and^ Sets:^ Dictionary^ Type^ In^ Python.

 Set is a collection which is unordered, unchangeable, and

unindexed. No duplicate members.

 Dictionary is a collection which is ordered and

changeable. No duplicate members.

1. Sets: Set class is used to represent the collection of elements

without duplicates, and without any inherent order to those

elements. It is enclosed by the {} and each element is

separated by the comma(,) and it is mutable.

Syntax:

d = {

: ,

: ,

:

2. Frozensets: It is an immutable form of a set, used to form a set

of the set.

Sets and frozensets support the following operators:

 key in s: It is used to check that the given key is in the set or

not.

 key not in s: it returns True if the key is not in the set.

3. Dictionaries: It is a mapping of different keys to its associated

values. We use curly brackets { } to create dictionaries too.

Del(Dictionary[key]) The method delete the entry match the key given.Giving non existing key will prompt an error

D2={3:90,4:89,2:89}

Del(D2[4]) Print(D2) #{3:90,2:89}

4 Explain Frozensets.

It is an immutable form of a set, used to form a set of the set.

Sets and frozensets support the following operators:

 key in s: It is used to check that the given key is in the set or

not.

 key not in s: it returns True if the key is not in the set.

Example:

s = {4, 5, 8, 6, 3, 2, 5}

key = 3

x = key in s

y = key not in s

print(x, y)

Output:

True False

1. Brief on Dictionary in Python.

A dictionary is a collection that is unordered, changeable, and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.  Key-value pairs  Unordered We can construct or create a dictionary like: X={1:’A’,2:’B’,3:’c’} X=dict([(‘a’,3) (‘b’,4)]X=dict(‘A’=1,’B’ =2) Example:

dict1 = {"brand":"mrcet","model":"college","year":2004} dict {'brand': 'mrcet', 'model': 'college', 'year': 2004} Operations and methods: Creating a Dictionary: You can create a dictionary using curly braces {} and specify key- value pairs separated by colons. Here's an example: my_dict = { "name": "John", "age": 30, "city": "New York" } Accessing Values: You can access values in a dictionary by referring to their keys. For example: name = my_dict["name"] Adding Key-Value Pairs: To add a new key-value pair to the dictionary, simply assign a value to a new key:

2 Explain^ about^ SET^ Methods.

The in-built methods of set are used to create, insert, remove and delete the set and set items. Method Description Example Set() Create empty set S1=set() Set(String) (^) Create set by splitting characters in given string as set item. Eliminates the repeated characters. S1=set(‘samples’) Print(S1) #{‘s’,’a’,’m’,’p’,’l’,’e’} len(set) Return number of items in set. S1={‘m’,’a’,’p’,’e’,’s’,’i’} print (len(set))

Set.add(Item) Adds the given item into the set S1=set() S1.add(2) S1.add(3) Print(S1) #{2,3} Set.copy() Create a copy of set. S1={2,3,5} S2=S1.copy() Print(S2) #{2,3,5} Set.update(items) Updates the existing set. The item can be string, list or tuple. The restrictions on update function :The empty set cannot be updated. The item cannot be numeric literal.

S1={1}

S1.update(‘a’) S2={4,3,2,5} S1. update(S2) Print(“Update:”S1) #Update:{1,2,,3,4,5,’a’} Set.remove(item) Remove the given item from set. It will prompt error when the item not in set.

S1={2,3,5}

S1.remove(2) Print(S1) #{3,5} Set.discard(item) (^) Remove the specified item if it exist.It will not prompt error if the item does not exist. S1={1,2,3,4,5,’a’} S1.discard(1) S1.discard(1) Print(“Discard Exist:”,S1 ) #{2,3,4,5,’a’} Set.pop() Removes the first element from the set S1={1,2,3,4,5} S1.pop() Print(“After Pop:”S1) #After Pop: {2,3,4,5} Set.clear() It removes all items from set and make it as empty set.

S1={2,3,5}

S1.clear() Print(S1) #set() del(Set) Removes the set given and the memory allocated for that also del(S1)