I'm newbie in python.
As I learned, str(123) returns the string format of value 123 which is '123'
but what if we have a variable named str, how can I call the str function?
In[2]: str(123)
Out[2]: '123'
In[3]: str='hello world'
In[4]: str(123)
Traceback (most recent call last):
File "/Users/x625/anaconda/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-4-6d97c31da288>", line 1, in <module>
str(123)
TypeError: 'str' object is not callable
How can I call str() function again?
stras a variable. However, you can still get to it usingimport builtinsand thenbuiltins.str.del strto be able to call it again. Fun fact this method of shadowing is used in security to prevent usage of harmful functions such as eval.