assertion error python

Assertions is one of the most advanced Exception Handling technique used in python by using the Assert statement,we can create debug message,if anything logically end up with an error.If anything fails logically AssertionError will display and end the process. here we will check assertion error python
When we are working with automatic car project their is a situation of fuel tank is empty that time we have to stop all process and stop the vehicle with an error message “no fuels”

See the syntax here

assert Expression[, Arguments]

Example:
Create a fuel.py file with below function

def fuelLevel(fuel):
   assert (fuel > 0),"Sorry no fuel in the system"
   print(fuel)

   
   
fuelLevel(4)
fuelLevel(0)

Run from command prompt

assertion error python

See All answers

  1. Good article! We will be linking to this particularly great content on our website.
    Keep up the great writing.

My Thought

Your email address will not be published. Required fields are marked *

Our Tool : hike percentage calculator