0% found this document useful (0 votes)
7 views62 pages

Module 4

Module 4 covers fundamental data types in Python including strings, lists, tuples, dictionaries, and sets, along with their operations. It explains how to create, access, update, and delete elements in these data structures, emphasizing their properties such as mutability and immutability. The module also introduces built-in methods for manipulating these data types effectively.

Uploaded by

seethalprince02
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)
7 views62 pages

Module 4

Module 4 covers fundamental data types in Python including strings, lists, tuples, dictionaries, and sets, along with their operations. It explains how to create, access, update, and delete elements in these data structures, emphasizing their properties such as mutability and immutability. The module also introduces built-in methods for manipulating these data types effectively.

Uploaded by

seethalprince02
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

MODULE 4

MODULE 4
OUTLINE

❑String and string operations,


❑List- creating list, accessing, updating and deleting elements
from a list, basic list operations.
❑Tuple- creating and accessing tuples in python, basic tuple
operations.
❑Dictionary, built in methods to access, update and delete
dictionary values.
❑Set and basic operations on a set.
S STRING AND STRING
FUNCTIONS
▪ Strings are one of the most popular data types in Python.
▪ Strings are created by enclosing various characters within quotes. Python does not
distinguish between single quotes and double quotes.
▪ Creating strings is very simple in Python
>>> var1 = ‘Hello Python!’
>>> var2 = ”Welcome to Python Programming!”
>>> print var1
‘Hello Python’ # Output
>>> print var2
‘Welcome to Python Programming’ # Output
▪ Strings are immutable. If you want to change an element of a string,
you have to create a new string
▪ Triple quoted strings can span to multiple lines.
▪>>> var = “““Welcome
to
Python
Programming”””
>>> prin(var)
Welcome
to
Python
Programming
▪ Strings are made up of smaller pieces/characters. The data types that are
made up of smaller pieces are known as compound data types.
▪ Strings, in Python, can be used as a single data type, or, alternatively, can
be accessed in parts.
▪ This makes strings really useful and easier to handle in Python.
▪ In order to access a part of the string, a square bracket operator ([]) must be
used.
>>> var = "hello"
>>> letter = var[4]
>>> print letter
o # Output
▪ len is a built-in function in Python.
▪ When used with a string, len returns the length or the number of characters in the
string
>>> var = “Hello Python!”
>>> len(var)
13 # Output
▪ We can use negative indices for accessing the string from last
>>> var = “Hello world”
>>> last = var[-1]
>>> second_last = var[-2]
▪ >>> print last
▪ d # Output
▪ >>> print second_last
▪ l # Output
▪ A piece or subset of a string is known as slice.
▪ Slice operator is applied to a string with the use of square braces ([]).
▪ Operator [n:m] will give a substring which consists of letters between n and m
indices, including letter at index n but excluding that at m, i.e. letter from nth
index to (m-1)th index.
▪ Similarly, operator [n:m:s] will give a substring which consists of letters from
nth index to (m-1)th index, where s is called the step value.
>>> var = ‘Hello Python’
>>> print var[0:4]
Hell # Output
▪ >>> print var[6:12]
▪ Python # Output
>>> alphabet = “abcdefghij”
>>> print alphabet[1:8:3]
beh # Output
▪ >>> print alphabet[1:8:2]
▪ bdfh # Output
▪ If we do not give any value for the index before the colon, i.e., n, then the slice will
start from the first element of the string. Similarly, if we do not give any value for the
index, i.e., m after the colon, the slice will extend to the end of the string.
▪ If we don’t give any value at both the sides of the colon, i.e., values for n and m are not
given then it will print the whole string.
▪ >>> var = ‘banana’
▪ >>> var[:4]
▪ ‘bana’ # Output
▪ >>> var[4:]
▪ ‘na’ # Output
▪ Traversal is a process in which we access all the elements of the string one
by one using some conditional statements such as for loop, while loop, etc.
▪ String traversal is an important pattern since there will be many situations
in different programs where we need to visit each element of the string and
do some operations, continuing till the end of the string.
▪ >>>var=‘banana’
OUTPUT
▪ >>> i=0
b
>>> while i < len(var): a
letter = var[i] n
a
print (letter) n
i=i+1 a
▪ String Concatenation is the technique of combining two strings.
▪ String Concatenation can be done using many ways.
▪ Using +,%,join operator etc
▪ Simplest method is to use + operator to add multiple strings together.
▪ However, the arguments must be a string.
▪var1 = "Hello "
var2 = "World"
var3 = var1 + var2
print(var3)
‘Hello World’#output
▪ The Concatenating strings with the “*” operator can create multiple
concatenated copies of same string.
▪print(“hello ”* 3)
hello hello hello#output
▪ Python has a set of built-in methods that you can use on strings.
▪ All string methods returns new values. They do not change the original
isalnum() Returns True if all characters in the string are
alphanumeric
capitalize() Converts the first character to upper case isalpha() Returns True if all characters in the string are in
the alphabet
casefold() Converts string into lower case isascii() Returns True if all characters in the string are
center() Returns a centered string ascii characters
count() Returns the number of times a specified value isdecimal() Returns True if all characters in the string are
occurs in a string decimals
encode() Returns an encoded version of the string isdigit() Returns True if all characters in the string are
digits
endswith() Returns true if the string ends with the isidentifier() Returns True if the string is an identifier
specified value
islower() Returns True if all characters in the string are
expandtabs() Sets the tab size of the string lower case
find() Searches the string for a specified value and isnumeric() Returns True if all characters in the string are
returns the position of where it was found numeric
isprintable() Returns True if all characters in the string are
format() Formats specified values in a string printable
isspace() Returns True if all characters in the string are
whitespaces
LIST AND LIST OPERATIONS IN
PYTHON
▪ List is a sequence of values called items or elements.
▪ The elements can be of any data type.
▪ The list is a most versatile data type available in Python which can be
written as a list of comma-separated values (items) between square
brackets.
▪ List are mutable, meaning, their elements can be changed.
▪ In Python programming, a list is created by placing all the items
(elements) inside a square bracket [ ], separated by commas.
▪ It can have any number of items and they may be of different types
(integer, float, string etc.).
▪ Method -1 without constructor
▪ # empty list
▪ my_list = []
Method-2 using list constructor
▪ # list of integers # empty list my_list = list()
▪ my_list = [1, 2, 3] # list of integers
▪ # list with mixed datatypes my_list = list([1, 2, 3])
▪ my_list = [1, "Hello", 3.4]
▪ # nested list
▪ my_list = [“welcome", [8, 4, 6]]
▪ Index operator [] is used to access an item in a list.
▪ Index starts from 0
▪ marks=[90,80,50,70,60]
▪ print(marks[0])
▪ Output: 90
▪ Nested list:
▪ my_list = [“welcome", [8, 4, 6]]
▪ print(my_list[1][0])
▪ Output: 8
▪ Python allows negative indexing for its sequences.
▪ The index of -1 refers to the last item, -2 to the second last item and so on

▪ my_list = ['p','r','o','b','e']

▪ print(my_list[-1])
▪ # Output: e

▪ print(my_list[-5])
▪ # Output: p
▪ To change elements use = operator with index[]
▪ >>> marks=[90,60,80]
▪ >>> print(marks)
▪ [90, 60, 80]
▪ >>> marks[1]=100
▪ >>> print(marks) [90, 100, 80]
▪ A new element or item can be added to an existing list using append() method.
▪ This method adds the item to the end of the list
▪ >>> marks=[90,60,80]
▪ >>> [Link](50)
▪ >>> print(marks)
▪ >>> [90, 60, 80, 50] #output
▪ To insert one item at a desired location use the method insert()
▪ >>[Link](index,element)
▪ >>> [Link](2,40)
▪ >>> print(marks)
▪ [90, 60, 40, 80, 50]
▪ extend Method: This method works like concatenation.
▪ It takes a list as an argument and adds it to the end of another list.
▪ >>> list1 = [‘x’,’y’,’z’]
▪ >>> list2 = [1,2,3]
▪ >>> [Link](list2)
▪ >>> print list1
▪ [‘x’, ‘y’, ‘z’, 1, 2, 3] # Output
>>>
▪ >>> [Link]([60,80,70])
▪ >>> print(marks)
▪ [90, 60, 40,80, 50, 60, 80, 70]
▪ Python provides many ways in which the elements in a list can be deleted
[Link](): pop() method is used to remove an item at the given index.
▪ The pop operator deletes the element on the provided index and stores that
element in a variable for further use
▪ >>> list = [10,20,30,40]
▪ >>> a = [Link](2)
▪ >>> print(list)
▪ [10,20,40] # Output
▪ >>> print (a)
▪ 30 # Output
2. del Operator :The del operator deletes the value on the provided index, but
it does not store the value for further use.
▪ It can even delete the list entirely.
>>> list = [‘w’,‘x’,’y’,’z’]
>>> del (list[1])
>>> print(list)
[‘w’, ‘y’, ‘z’] # Output
▪ >>> del list
▪ >>>print (list)
▪ Name Error: name ‘list' is not defined
clear() method: to empty a list.
▪ [Link]()
▪ print(list)
▪ [] #output
3. remove Operator
▪ We use the remove operator if we know the item that we want to remove
or delete from the list (but not the index).
>>> list = [10,20,30,40]
>>> [Link](10)
>>> print(list)
[20,30,40] # Output
▪ In order to delete more than one value from a list, del operator with slicing is
used.
>>> list = [1,2,3,4,5,6,7,8]
>>> del list[1:3]
>>> print (list)
[1,4,5,6,7,8] # Output
▪ Slicing = list[start:stop:step]
▪ Concatenation = +
▪ Repetition= *
▪ Membership = in
▪ 1. Concatenation
▪ The concatenation operator works in lists in the same way it does in a
string. This operator concatenates two lists. This is done by the + operator
in Python
▪ >>> list1 = [10,20,30,40]
▪ >>> list2 = [50,60,70]
▪ >>> list3 = list1 + list2
▪ >>> print (list3)
▪ [10,20,30,40,50,60,70] # Output
▪ 2. Repetition
▪ The repetition operator works as suggested by its name; it repeats the
list for a given number of times.
▪ Repetition is performed by the * operator.
▪ >>> list1 = [1,2,3]
▪ >>> list1 * 4
▪ [1,2,3,1,2,3,1,2,3,1,2,3] # Output
▪ >>> [2] * 6
▪ [2,2,2,2,2,2] # Output
▪ 3. In Operator
▪ The In operator tells the user whether the given element exists in the list or not.
▪ It gives a Boolean output, i.e., True or False.
▪ If the given input exists in the list, it gives True as output, otherwise, False
▪ >>> list = [‘Hello’, ‘Python’, ‘Program’]
▪ >>> ‘Hello’in list
▪ True # Output
▪ >>> list = [10,20,30,40]
▪ >>> 10 in list
▪ True # Output
▪ >>> 50 in list
▪ False # Output
[Link]
▪ List can be sliced in the same way as strings
▪ list[start:stop:step]
▪ list[n:m] produces a slice with elements from index n to index m-1
▪ list=[2,3,4,5,6]
▪ print(list[1:4])
▪ [3,4,5]
▪ print(list[-4:-1])
▪ [3,4,5]
TUPLE
▪ Tuples are the sequence or series values of different types separated by
commas (,) and enclosed in paranthesis().
▪ Just like strings and lists, values in tuples can also be accesed by their
index values, which are integers starting from 0.
▪ Major differences from lists are
▪ Immutable
▪ Enclosed in parentheses
▪A tuple with a single element must have a comma inside the parentheses:
a = (11,)
▪ >>> mytuple = (11, 22, 33)
▪ >>> mytuple[0]
11
▪ >>> mytuple[-1]
33
Method-2 using tuple constructor
▪ Method -1 without constructor
# empty tuple my_tup = tuple() # tuple of integers
▪ # empty tuple
▪ tup= ()
▪ # tuple of integers
▪ my_tup = (1, 2, 3) ▪ Method-2 using tuple constructor
▪ # tuple with mixed datatypes my_tup = tuple((1, 2, 3))
▪ my_tup = (1, "Hello", 3.4)
▪ # nested tuple
▪ my_tup = (“welcome", (8, 4, 6))
▪ Tuple can also be created without parenthesis
▪ >>>tuple =4.9,6,’house’
▪ >>>print(tuple)
▪ (4.9, 6, ‘house’)
▪ Using square brackets
▪ >>>tup1 = (‘Physics’,’chemistry’,’mathematics’)
▪ >>>tup2 = (10,20,30,40,50)
▪ >>>print(tup1[1])
▪ Chemistry # Output
▪ >>>print(tup2[4])
▪ 50 # Output
▪ >>>print (tup1[-2])
▪ chemistry # Output
▪ Using slicing
▪ In order to print the continuous values in a tuple slicing can be used.
▪ >>>tup1 = (‘Physics’,’chemistry’,’mathematics’)
▪ >>>tup2 = (10,20,30,40,50)
▪ >>>tup2[1:4]
▪ (20, 30, 40) # Output
▪ >>>tup1[:1]
▪ (‘Physics’,) # Output
▪ >>>tup1[:2]
▪ (‘Physics’, ‘chemistry’) # Output
▪ Tuples are immutable. The values or items in the tuple cannot be changed
once it is declared.
▪ If we want to change the values, we have to create a new tuple.
▪ # declaring a tuple
▪ >>>tup = (12, 15, “Python”, 2.3)
▪ # change the 3rd element “Python” to “Hello”
▪ >>>tup[2] = “Hello”
▪ TypeError: ‘tuple’object does not support item assignment
▪ It allows the assignment of values to a tuple of variables on the left side of the
assignment from the tuple of values on the right side of the assignment.
▪ The number of variables in the tuple on the left of the assignment must match
the number of elements/items in the tuple on the right of the assignment
▪ # creating a tuple
▪ >>>Anu = (‘221’,’Anu’,’Rahul’,’Delhi’,1971,’Jaipur Gwalior’)
▪ # tuple assignment
▪ >>>(id,fst_name,lst_name,city,year_of_birth,birth_place) = Anu
▪ >>>print (id)
▪ 221 # Output
▪ >>>print (fst_name)
▪ Anu # Output
▪ Using tuple assignment two values x,y can be swapped without using a
temporary variable
▪ >>>x = 3
▪ >>>y = 4
▪ >>>x , y = y , x # Using tuple assignment
▪ >>>print(x)
▪ 4 # Output
▪ >>>print(y)
▪ 3 # Output
▪ 1. Concatenation
▪ The concatenation operator works in tuples in the same way as it does in lists.
▪ This operator concatenates two tuples. This is done by the + operator in Python
▪ >>>t1 = (1,2,3,4)
▪ >>>t2 = (5,6,7,8)
▪ >>>t3 = t1 + t2
▪ >>>print(t3)
▪ (1, 2, 3, 4, 5, 6, 7, 8) # Output
▪ 2. Repetition
▪ The repetition operator works as its name suggests; it repeats the tuples a given
number of times.
▪ Repetition is performed by the* operator in Python.
▪ >>>tuple = (‘ok’,)
▪ >>>tuple * 5
▪ (‘ok’, ‘ok’, ‘ok’, ‘ok’, ‘ok’) # Output
▪ >>>(‘Hello’,) * 3
▪ (‘Hello’, ‘Hello’, ‘Hello’) # Output
▪ 3. in Operator
▪ The in operator also works on tuples.
▪ It tells user that the given element exists in the tuple or not.
▪ It gives a Boolean output, that is, TRUE or FALSE.
▪ If the given input exists in the tuple, it gives the TRUE as output, otherwise
FALSE.
▪ >>>tuple = (10,20,30,40)
▪ >>>20 in tuple
▪ True # Output
▪ >>>50 in tuple
▪ False # Output
▪ 4. Iteration
▪ Iteration can be done in tuples using for loop. It helps in traversing the tuple.
▪ >>>tuple = (1,2,3,4)
for x in tuple:
... print (x)
Output:
1
2
3
4
Function Description
len(tuple) It returns the length of a tuple
zip(tuple1, tuple2) It ‘zips’ elements from two tuples into a list of tuples.
max(tuple) It returns the largest value among the elements in a tuple
min(tuple) It returns the smallest value among the elements in a tuple
tuple(seq) It converts a list into a tuple.
DICTIONARY AND DICTIONARY OPERATIONS
IN PYTHON
▪ The Python dictionary is an unordered collection of items or elements.
▪ All
other compound data types in Python have only values as their elements or items
whereas the dictionary has a key: value pair. Each value is associated with a key.
▪ In the list
and the tuple, there are indices that are only of integer type but in dictionary,
we have keys and they can be of any type.
▪ Dictionary issaid to be a mapping between some set of keys and values. Each key
is associated to a value.
▪ The mapping of a key and value is called as a key-value pair and together they are
called one item or element.
▪ A key and its value are separated by a colon (:) between them.
▪ The items or elements in a dictionary are separated by commas and all the elements
must be enclosed in curly braces.
▪ A pair of curly braces with no values in between is known as an empty dictionary.
▪ The values in a dictionary can be duplicated, but the keys in the dictionary are unique.
▪ The values in a dictionary can be of any data type, but the keys must be of
immutable data types (such as string, number or tuple).
▪ Empty Dictionary
Method-2 using dict()
▪ >>> dict1 = {}
# empty dictionary
▪ >>>print dict1
dic= dict()
▪ {} # Output
Dictionary with integer keys
▪ Dictionary with integer keys >>>d1= dict({1:’red’, 2:’yellow’,3:’green’})
▪ >>> dict1 = {1:’red’,2:’yellow’,3:’green’}
▪ >>>print dict1
▪ {1: ‘red’, 2: ‘yellow’, 3: ‘green’} # Output
▪ Dictionary with mixed keys
▪ >>> dict1 = {‘name’: ‘jinnie’, 3:[‘Hello’,2,3]}
▪ >>>print dict1
▪ {3: [‘Hello’, 2, 3], ‘name’: ‘jinnie’} # Output
▪ In order to access the elements from a dictionary, we can use the value of the
key enclosed in square brackets.
▪ Python also provides a get() method that is used with the key in order to access
the value.
▪ >>> dict1 = {‘name’: ‘John’, ‘age’ : 27}
▪ >>> dict1[‘name’]
▪ ‘John’ # Output
▪ >>> print (dict1[‘age’])
▪ 27 # Output
▪ >>> [Link](‘name’)
▪ ‘John’ # Output
▪ >>> [Link](‘age’)
▪ 27 # Output
▪ Dictionaries in Python are mutable.
▪ If the key is present in the dictionary, then the associated value with that key is
updated or changed; otherwise a new key: value pair is added.
▪ >>> dict1 = {‘name’: ‘John’, ‘age’: 27}
▪ >>> dict1[‘age’] = 30 # updating a value
▪ >>> print(dict1)
▪ {‘name’: ‘John’, ‘age’: 30 } # Output
▪ >>> dict1[‘address’] = ‘Alaska’ # adding a key: value
▪ >>>print(dict1)
▪ {‘name’: ‘John’, ‘age’: 30, ‘address’: ‘Alaska’} # Output
▪ The items or elements from a dictionary can be removed or deleted by using pop()method.
▪ pop()method removes that item from the dictionary for which the key is provided. It also
returns the value of the item.
▪ popitem()method is used to remove or delete and return an arbitrary item from the dictionary.
>>>dict_cubes = {1:1, 2:8, 3:9, 4:64, 5:125, 6:216}
>>>dict_cubes.pop(3) # remove a particular item
9 # Output
>>>dict_cubes
{1: 1, 2: 8, 4: 64, 5: 125, 6: 216} # Output
>>>dict_cubes.popitem() remove an arbitrary item
(1, 1) # Output
>>>dict_cubes.popitem()
(2, 8) # Output
>>>dict_cubes
{4: 64, 5: 125, 6: 216} # Output
▪ del() method can be used to delete an item
▪ This can be used to delete the dictionary itself. When this operation is performed, the
dictionary is deleted from the memory and it ceases to exist
▪ del dict_cubes[6] # delete a particular item
▪ >>>dict_cubes
▪ {4: 64, 5: 125} # Output
▪ The clear() method removes all the items or elements from a dictionary at once. When
this operation is performed, the dictionary becomes an empty dictionary.
▪ >>>dict_cubes.clear() # remove all items
▪ >>>dict_cubes
▪ {} # Output
▪ >>>del dict_cubes # delete the dictionary itself
▪ >>> print (dict_cubes)
▪ NameError: name ‘dict_cubes’is not defined
▪ 1. Traversing
▪ Traversing in dictionary is done on the basis of keys because they are unique.
▪ For this, for loop is used, which iterates over the keys in the dictionary and
prints the corresponding values using keys
▪ dict = {1:’a’,2:’b’,3:’c’,4:’d’}
for c in dict
print(c,dict[c])

Output:
1a
2b
3c
4d
▪ 2. Membership
▪ Using the membership operator (in and not in), we can test whether a key is in
the dictionary or not
▪ It takes an input key and finds the key in the dictionary. If the key is found, then
it returns True, otherwise, False
▪ >>>cubes = {1:1, 2:8, 3:27, 4:64, 5:125, 6:216}
▪ >>>3 in cubes
▪ True # Output
▪ >>>7 not in cubes
▪ True # Output
▪ >>>10 in cubes
▪ False # Output
▪ len(dict): It returns the number of items (length) in the dictionary.
▪ sorted(dict) :It returns the sorted list of keys.
▪ str(dict): It produces a printable string representation of the dictionary.
▪ [Link]() :It returns a copy of the dictionary.
▪ [Link](key, default=None) :For key key, returns value or default if key not in
dictionary.
▪ dict.has_key(key): It finds the key in dictionary; returns True if found and false
otherwise.
▪ [Link]() :It returns a list of entire key: value pair of dictionary.
▪ [Link]() :It returns the list of all the keys in dictionary.
▪ [Link](): It returns all the values in the dictionary
SETS AND SET OPERATIOS IN PYTHON
▪ Mathematically a set is a collection of items not in any particular order.
▪ A Python set is similar to this mathematical definition with some additional
features.
▪ The elements in the set cannot be duplicates.
▪ The elements in the set are immutable(cannot be modified) but the set as a whole is
mutable.
▪ There is no index attached to any element in a python set. So they do not support
any indexing or slicing operation.
▪ A set is created by using the set() function or placing all the elements
within a pair of curly braces.
▪ S=set() #empty set
▪ Days=set(["Mon","Tue","Wed","Thu","Fri","Sat","Sun"])
▪ Months={"Jan","Feb","Mar"}
▪ Dates={21,22,17}
▪ print(Dates)
▪ {21,22,17} #output
▪ We cannot access individual values in a set. We can only access all the elements
together
▪ But we can also get a list of individual elements by looping through the set.
▪ Days=set(["Mon","Tue","Wed“,”Thu","Fri","Sat","Sun"])
for d in Days:
print(d)
Output
Wed
Sun
Fri
Tue
Mon
Thu
Sat
▪ We can add elements to a set by using add() method.
▪ There is no specific index attached to the newly added element.
▪ Days=set(["Mon","Tue","Wed”])
▪ [Link]("Sun")
▪ print(Days)
▪ {“Mon”,”Sun”,”Tue”,”Wed”} #output
▪ We can remove elements from a set by using discard() method.
▪ Days=set(["Mon","Tue","Wed",“Sun"])
▪ [Link]("Sun")
▪ print(Days)
▪ {“Mon,”Tue”,”Wed”}
▪ The union operation on two sets produces a new set containing all the distinct
elements from both the sets.
▪ Example
▪ DaysA = set(["Mon","Tue","Wed"])
▪ DaysB = set(["Wed","Thu","Fri","Sat","Sun"])
▪ AllDays = DaysA | DaysB
▪ print(AllDays)
▪ {'Wed', 'Fri', 'Tue', 'Mon', 'Thu', 'Sat’} #Output
▪ Can also be accomplished by union() method
▪ Print([Link](DaysB))
▪ The intersection operation on two sets produces a new set containing only the
common elements from both the sets.

▪ Example
▪ DaysA = set(["Mon","Tue","Wed"])
▪ DaysB = set(["Wed","Thu","Fri","Sat","Sun"])
▪ AllDays = DaysA & DaysB
▪ print(AllDays)
▪ {‘Wed’} #Output
▪ The difference operation on two sets produces a new set containing only the
elements from the first set and none from the second set.

▪ Example
▪ DaysA = set(["Mon","Tue","Wed"])
▪ DaysB = set(["Wed","Thu","Fri","Sat","Sun"])
▪ AllDays = DaysA - DaysB
▪ print(AllDays)
▪ set(['Mon', 'Tue’]) #Output
▪ We can check if a given set is a subset or superset of another set.
▪ The result is True or False depending on the elements present in the sets.
▪ Example
▪ DaysA = set(["Mon","Tue","Wed"])
▪ DaysB = set(["Mon","Tue","Wed","Thu","Fri","Sat","Sun"])
▪ Sub = DaysA <= DaysB
▪ Sup = DaysB >= DaysA
▪ print(Sub)
▪print(Sup)
#Output
▪ True
▪ True

You might also like