How to exit a loop in Python? Replace exit with break. Exit isn’t a way to exit loops in Python. break statement docs