Can you explain the difference between a 'try' and a 'except' block in Python?

Responsive Ad Header

Question

Grade: Education Subject: Support
Can you explain the difference between a 'try' and a 'except' block in Python?
Asked by:
78 Viewed 78 Answers

Answer (78)

Best Answer
(251)
A 'try' block attempts to execute a block of code. If an exception occurs, the 'except' block is executed. The 'try' block is the first place the code is executed, and the 'except' block is executed only if an exception occurs within the 'try' block.