An AttributeError
will occur if you try to access a method that does not exists:
x = "Hello"
print(x.toUpperCase())
The AttributeError
exception occurs when you try to execute a property or method that does not exist on the current object.
You can handle the AttributeError
in a try...except
statement, see the example below.
Handling the AttributeError
in a try...except
statement:
x = "Hello"
try:
print(x.toUpperCase())
except AttributeError:
print("Oops! Strings do not have a toUpperCase method!")
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