Skip to content

Instantly share code, notes, and snippets.

@byung-u
Last active March 10, 2022 21:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save byung-u/957f2094438b06283810ff0985e545d3 to your computer and use it in GitHub Desktop.
Save byung-u/957f2094438b06283810ff0985e545d3 to your computer and use it in GitHub Desktop.
Exit while loop by user hitting enter key (python)
#!/usr/bin/env python3
# http://stackoverflow.com/questions/7255463/exit-while-loop-by-user-hitting-enter-key
while True:
i = input("Enter text (or Enter to quit): ")
if not i:
print("excape") # Enter key to quit
break
print("Your input:", i)
@pangeon
Copy link

pangeon commented Apr 12, 2021

Good hint, thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment