Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

Python에서 무한 루프를 중지하려면 어떤 키보드 명령이 필요합니까?


모든 루프는 특정 횟수 또는 특정 조건이 충족될 때까지 실행되도록 구성됩니다. 그러나 조건이 발생하지 않으면 루프가 계속 무한반복됩니다. 이러한 무한 루프는 키보드 인터럽트를 생성하여 강제로 중지해야 합니다. Ctrl-C를 누르면 무한 루프 실행이 중지됩니다.

>>> while True:
print ('hello')


hello
hello
hello
hello
hello
hello
Traceback (most recent call last):
File "<pyshell#18>", line 2, in <module>
print ('hello')
KeyboardInterrupt