Skip to content

Python input enter pressed | Example code

  • by

Create a While True loop that calls for input until the input differs from the empty string to check input enter pressed or not in Python.

You can also use a simple if statement with the input value. If Text is empty then it means enter has been pressed by the user.

Example get know user input enter pressed in Python

Simple example code check user will hit enter and you will check if it was entered or not.

guess = ""

while True:
    if guess == "":
        guess = input("Please Enter a letter! ")



Python input enter pressed

Detect Enter has pressed

text = input("type in enter")  # or raw_input in python2
if text == "":
    print("you pressed enter")
    print("you typed some text before pressing enter")


type in enter
you pressed enter

Do comment if you have any doubts or suggestions on this Python input topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Your email address will not be published. Required fields are marked *