[Python] In Python Version 3.13.5 is Once you used set or any Data Structure in One Code Cell...

Discussão em 'Python' iniciado por Stack, Junho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am using Python 3.13.5 in a Jupyter Notebook (inside VS Code) and ran into a TypeError.

    First, I created a set, which worked fine:

    Python

    my_set = {1, 2, 3, 4, 5}
    print(my_set)


    Then, in a different cell, I accidentally reassigned the built-in set name to a variable:

    Python

    '''The problematic line '''
    set = set()


    After executing that line, any subsequent attempt to create a set using the set() constructor fails. For example:

    Python

    S_set = set({1, 2, 3, 4, 5, 6})


    This code now throws the following error:

    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    TypeError: 'set' object is not callable


    My understanding is that I have overwritten the built-in set constructor with an instance of a set object. Could someone confirm if this is the correct diagnosis and explain why this specific TypeError occurs? What is the best practice to avoid this kind of issue in Python?

    In that IDE, I use the set() module in code cells 1 & 2, and then I use it in the 3rd code cell, which gives an error on that, but that same code runs in also 3.13.1 version.

    I show an Error in my IDE https://i.sstatic.net/oYPaMyA4.png

    Continue reading...

Compartilhe esta Página