Week-5(Tuples and Sets)

Dear Team,

Requesting you to please revert to the below queries:

  1. Are sets mutable ?
  2. For the input “%%timeit -n1 -r10
    for i in range(10000):
    b=1947 in my_set” Why are we not using {} which indicates sets ?

Thanks and Regards,
Purvi Manghi

In the 2. point, 2nd line
my_set=set(range(10000))—is where my question is why not using {} in the input.

Thanks & Regards,
Purvi Manghi


  1. There are two types of sets in python.
    A. set() This function is used to create mutable sets.
    B. frozenset() This is used to create immutable set.

  2. We’re using parentheses (which looks like *()*) because we’re calling a function set() to create a set from an iterable object. That object is returned when we called range(10000)



In the above step, you are calling the range function with parameter 10k which will return an object of type range and calling set() on the range output will convert the object of range type to set which we call as Typecasting.

To answer your question, {} is how we initialize a dictionary in Python; dict() is other way of it. Sets will always be initialized or typecasted using set() method as done in your example.