In Python, sets are collections of unique elements. To create a set of size N with different types of items, you can use the built-in set
function.
In this example,
set
function to create a set named string_set
with initial string elements.len
function.string_set = set(['apple', 'banana', 'cherry'])
print('Size of string_set:', len(string_set))
Size of string_set: N
In this example,
set
function to create a set named int_set
with initial integer elements.len
function.int_set = set([1, 2, 3])
print('Size of int_set:', len(int_set))
Size of int_set: N
In this tutorial, we learned How to create a Set of size N in Python language with well detailed examples.