How to fix “str” object is not callable when using set() function in Python 3.6.4
This happens if you have assigned str to some value. I think, the problem is not with the set in your case.
1. Error Free :
Let’s see an example:
- >>> ones = 2
- >>> tens = 3
- >>> number = str(tens) + str(ones)
- >>> number
- '32'
Here, everything is working as expected.
Now, let’s see the type of str to see why we are not getting:
‘str’ object is not callable
I check the type in python console.
- >>> type(str)
Since it is of type, it must be callable.
I’m going to use callable() for this purpose just to be sure.
- >>> callable(str)
- True
2. Replicating error:
Now let’s try to replicate your error.
What I’m going to do is assign str to some arbitary type value.
- >>> str = "dont do this"
- >>> type(str)
Wait, what??
str is no more of type type??
Now, check if callable.
- >>> callable(str)
- False
What does this mean?
Try copying the snippet:
- >>> ones = 2
- >>> tens = 3
- >>> number = str(tens) + str(ones)
- Traceback (most recent call last):
- File "", line 1, in
- TypeError: 'str' object is not callable
We get the
TypeError: 'str' object is not callable
We are no more able to use str() as function as we have assigned some value to str .
3. FIX:
I think now you know how to fix the problem by yourself now. Just search the places if you have used str as variable. This should fix it.
If it doesn’t fix the issue, feel free to attach code snippets.
Artigos semelhantes
- What does 'str' object does not support item assignment' error mean in python?
- O que faz 'Erro: Só pode concatenar str (não "int") a str' significar em Python?
- Como resolver TypeError: tipo(s) de operando não suportado(s) para -: 'str' e 'str' em Python
- Is there any way in c to change the value of a global variable through a function without passing it to the function?