A TypeError
occurs if you try to concatenate a string and a number:
x = "hello"
y = 15
print(x + y)
The TypeError
exception occurs if an operation tries to perform an action with an unexpected data type.
You can handle the TypeError
in a try...except
statement, see the example below.
Handling the TypeError
in a try...except
statement:
try:
x = "hello" + 15
except TypeError:
print("Please convert to string before concatenate")
except:
print("Something else went wrong")
Track your progress - it's free!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4