Casa > H > How To Fix “Str” Object Is Not Callable When Using Set() Function In Python 3.6.4

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:

  1. >>> ones = 2 
  2. >>> tens = 3 
  3. >>> number = str(tens) + str(ones) 
  4. >>> number 
  5. '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.

  1. >>> type(str) 
  2.  

Since it is of type, it must be callable.

I’m going to use callable() for this purpose just to be sure.

  1. >>> callable(str) 
  2. 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.

  1. >>> str = "dont do this" 
  2. >>> type(str) 
  3.  

Wait, what??

str is no more of type type??

Now, check if callable.

  1. >>> callable(str) 
  2. False 

What does this mean?

Try copying the snippet:

  1. >>> ones = 2 
  2. >>> tens = 3 
  3. >>> number = str(tens) + str(ones) 
  4. Traceback (most recent call last): 
  5. File "", line 1, in  
  6. 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.

De Maryjo

Quais são algumas novas estratégias de monetização de aplicativos móveis para jogos? :: Qual Mach é a velocidade da luz?