
message = "I love Python"
print(message())
Error as in PyCharm:
Traceback (most recent call last):
File "/Users/code2care/PycharmProjects/python-learnings/0-test.py", line 2, in <module>
print(message())
TypeError: 'str' object is not callable
Error as in Jupyter Notebook:
TypeError Traceback (most recent call last)
Cell In[22], line 2
1 message = "I love Python"
----> 2 print(message())
TypeError: 'str' object is not callable
Reason for this error
As the error describes, it is a type error! where in the string object is treated as a function with parenthesis.
One of the other most common cause of this issue is if you define a variable of any datatype (int, float, list, tuple, dist, etc) and you name it as str and try to cast it to a string using the str function.
str = [1,2,3,4,5]
print(str(str))
Error:
Cell In[28], line 2
1 str = [1,2,3,4,5]
----> 2 print(str(str))
TypeError: 'list' object is not callable
How to fix this error
The fix is simple, just remove the parenthesis () from the line where an str object is treated as a function mistakenly.
message = "I love Python"
print(message)
-
Have Questions? Post them here!
More Posts related to Python,
- Check version of pip package installer for Python
- How to install Python 3.9 using brew on Mac
- Python Program To Calculate Simple Interest (SimpleInterest.py)
- Indent Python code in Notepad++
- Change label (text) color in tkinter
- Float built-in function in Python
- [Fix] ValueError: substring not found in Python
- pip get list of all outdated Python packages
- Calculate discount amount python code
- 3 Python program to add two numbers
- How to List all Packages installed using pip [Python]
- Python range() function examples
- How to resolve Failed to create interpreter PyCharm Error
- Format Python Code in Visual Studio Code (VS Code)
- Validate email address in Python using regular expression (regex)
- Install and Run Jupyter Notebook on Mac (macOS)
- How to delete a file using Python code example
- Base64 Encoding Decoding in Python Programming
- How to pip install Python Modules in VSCode
- Change the background of Tkinter label or text
- Comments in Python Programming
- Take input argument from command line in Python Programming
- How to Convert Python String to DateTime Object
- Tkinter - add x and y padding to label text
- [Tutorial] Install Python on Visual Studio Code (VS Code)
More Posts:
- 21 Useful Android Emulator Short-cut Keyboard Keys - Android
- Command to display epoch time Terminal - Linux
- Save a Notepad file as Microsoft Excel file - Microsoft
- Calculate Area of Parallelogram - C-Program
- Sharepoint Server 2016 installation Prerequisites with download links - SharePoint
- Spell check not working in Gmail : Mac OS X - Mac-OS-X
- How to kill tomcat server process using Mac Terminal Command - Tomcat
- How to Change Android Toast Position? - Android