How to know if a user has pressed the Enter key using Python -
how know if user has pressed enter using python ?
for example :
user = raw_input("type in enter") if user == "enter": print "you pressed enter" else: print "you haven't pressed enter"
as @jonrsharpe said, way exit raw_input
function pressing enter. solution check if result contains or not:
text = raw_input("type in enter") if text == "": print "you pressed enter" else: print "you typed text before pressing enter"
the other ways see quit raw_input
function throw exception such as:
eoferror
if type^d
keyboardinterrupt
if type^c
- ...
Comments
Post a Comment