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

Python Set Manipulation Program

The document outlines a practical exercise to manipulate sets in Python, including creating, accessing, updating, and deleting elements from a set. It provides example code snippets demonstrating how to add and remove items, as well as how to find the maximum and minimum values in a set. Additionally, it shows how to count the number of elements in a set.

Uploaded by

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

Python Set Manipulation Program

The document outlines a practical exercise to manipulate sets in Python, including creating, accessing, updating, and deleting elements from a set. It provides example code snippets demonstrating how to add and remove items, as well as how to find the maximum and minimum values in a set. Additionally, it shows how to count the number of elements in a set.

Uploaded by

Tanisha Waichal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical- 10

LLO: Write a python program to manipulate the set.

Program: Write python program to perform following operations on the Set;


Create set, Access Set, Update Set, Delete Set:

My_set = {1, 2, 3, 4, 5}

Print(“Set:”, my_set)

For item in my_set:

Print(“Accessed item:”, item)

My_set.add(6)

Print(“Updated Set (after adding 6):”, my_set)

My_set.remove(3)

Print(“Updated Set (after removing 3):”, my_set)

Del my_set

O/P:

PRQs: -
A3.

My_set = {1, 2, 3, 4, 5}

My_set.add(6)

My_set.add(7)

Print(“Set after adding members:”, my_set)

My_set.remove(4)

Print(“Set after removing 4:”, my_set)

O/P:

A4.

My_set = {10, 20, 5, 30, 15}

Print(“Maximum value:”, max(my_set))

Print(“Minimum value:”, min(my_set))

O/P:

A5.

My_set = {10, 20, 30, 40, 50}


Count = 0

For item in my_set:

Count += 1

Print(“Length of the set:”, count)

O/P:

You might also like