A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3schools.com/python/ref_exception_attributeerror.asp below:

Website Navigation


Python AttributeError Exception

Python AttributeError Exception

❮ Python Exceptions

Example

An AttributeError will occur if you try to access a method that does not exists:

x = "Hello"
print(x.toUpperCase())

Try it Yourself » Definition and Usage

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.

Exception Handling Example

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")

Try it Yourself »

❮ Python Exceptions

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