You are currently viewing How To Use Sets In Python? Learn Python Advance 2021
how to use sets in python

How To Use Sets In Python? Learn Python Advance 2021

How To Use Sets In Python? What are the sets in python?

A python sets are the consist of element which are store in shape of array. You can add a element or remove any element. By default these sets are unordered you can ordering these as you want.

Sets can also be used to perform mathematical operations like union , intersection and differences etc.

How to create set in python ?

The sets of elements are written inside the curly bracket {} and each element separated by comma , or built in function  set().The item in the sets may be the number, string, date, time and float etc.

Following these simple step to create your first set in python.

Step 01. Open PyCharm and create new project

Step 02. Right click on you project which you have created, Select new and then choose python file.

Step 03. Enter the name of python file i.e Sets.

how to use sets in python

Stpe 04. Enter the name of set in your file like A and create items in sets as you want. 

Example of Sets:

#integer set example
A = {1, 2, 3, 4, 5}
print(A)
Output is:
{1, 2, 3, 4, 5}

#set of mixed datatype
B = {2, 3.4, "gsstech", (2, 4, 8)}
print(B)

The output is :
{'gsstech', 2, (2, 4, 8), 3.4}

This Post Has One Comment

Comments are closed.