Home >>Python Keywords >Python try Keyword

Python try Keyword

Python try Keyword

Python try keyword is used to defines a block of code and used in try except blocks. You can execute blocks if nothing went wrong and define different blocks for different error types.

Here is an example of Python try Keyword:

try:
  z > 5
except:
  print("Something went wrong")
print("Even if it raised an error, the program keeps running")

Output:
Something went wrong
Even if it raised an error, the program keeps running
Example 2:

try:
  y > 13
except:
  print("all is not good")
print("Even if it raised an error, the program keeps running")

Output:
all is not good
Even if it raised an error, the program keeps running

No Sidebar ads