📚 › Python: the friendliest first language
13. Handling errors with try and except
Este artículo se traducirá automáticamente. Por ahora se muestra en inglés.
try runs code that might fail, and except handles the error. Without it, a single mistake stops the whole program.
Read the error message: it names the problem and the line.
Ver ejemplo
try:
print(10 / 0)
except ZeroDivisionError:
print("Cannot divide by zero")
✍️ Ahora te toca
Use try and except: in try divide 1 by 0, in except print Cannot divide.