Use a while loop that only terminates if the length of name is 0:

name = ""
while len(name) == 0:
    print("What is your name?")
    name = input()
print("Hi, {}".format(name))
Answer from BrokenBenchmark on Stack Overflow
🌐
Sololearn
sololearn.com › en › Discuss › 1582033 › how-to-check-if-input-is-empty-in-python
How to check if input is empty in python? | Sololearn: Learn to code for FREE!
One pattern would be: s = input() ... somelist.append(s) ... input() returns a string. To check whether it is empty, just check its length....
🌐
Reddit
reddit.com › r/learnpython › empty input
r/learnpython on Reddit: Empty input
October 17, 2020 -

I need to write a program that asks for numbers from an user until the user gives "an empty input". I am stuck on this empty input part in particular. I have Googled for hours and hours but haven't found anything that would match and help me.

lst = []

user_input = int(input("Please enter a number: "))

while user_input != 0:
lst.append(user_input)

user_input = int(input("Please enter a number: "))

if user_input == 0:
break
print("You said: ", lst)

This example works, because it has 0, not completely empty input. How do I change the 0 to just empty?

if user_input == "":
break

This doesn't work? Where am I going wrong here?

🌐
Bobby Hadz
bobbyhadz.com › blog › python-check-if-input-is-empty
How to check if User Input is Empty in Python | bobbyhadz
Copied!country = input('Where are you from: ') if country == '': print('User input is empty') else: print('User input is NOT empty') ... The first example uses an if statement to check if a user input is empty.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-to-check-if-string-is-empty-or-not
Check if String is Empty or Not - Python - GeeksforGeeks
July 11, 2025 - So, we can use this for checking if a string is empty or not. ... The string is empty. Explanation: "not s" negates the boolean value of s, if it's empty then it's boolean quivalent to False and its negation would be True.
🌐
Data Science Parichay
datascienceparichay.com › home › blog › python – check if input is empty
Python - Check If Input Is Empty - Data Science Parichay
October 17, 2022 - Values from the standard input are read as strings in Python. So, to check if the input is empty use the equality operator == in Python to check if the input string is equal to an empty string or not.
🌐
ProgrammingBasic
programmingbasic.com › home › python › check if user input is empty in python
Check if user input is empty in python | ProgrammingBasic
The input function returns the user input data as a string. To detect if the user input is an empty string, we can use the if statement to compare the user input with an empty string, eg user_input == ''.
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › python › check if a string is empty in python
Check if a string is empty in Python | Sentry
If we want to ensure that my_string is an empty string and not a different false-equivalent value, we should do the following: ... if my_string == "": print("my_string is an empty string!") else: print("my_string is not an empty string!") A string ...
🌐
YouTube
youtube.com › watch
How To Check User Input Empty In Python 2023 - YouTube
Check If Python Input Box Is Empty. Two Simple Python Code Examples For Beginners.#pythonbeginners #pythoncode
Published   December 4, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-check-if-variable-is-empty-in-python
How To Check If Variable Is Empty In Python? - GeeksforGeeks
July 23, 2025 - Below are some of the ways by which we can check if the variable is empty in Python or not: ... In this example, the code checks if the length of the list (`my_list`) is zero using `len()`. If the length is zero, it prints "Empty Variable"; otherwise, it prints "Not Empty Variable," providing a simple way to determine whether the list is empty or not. ... my_list = [] if len(my_list) == 0: print("Empty Variable") else: print("Not Empty Variable")
🌐
Python Pool
pythonpool.com › home › blog › 7 quick ways to check if string is empty in python
7 Quick Ways to Check If String is Empty in Python - Python Pool
May 4, 2023 - NOTE: If the string contains spaces in it the string is not treated as the empty string by using the len() function in python · Let us look at the example for the better understanding of the concept: #input empty with and without spaces string ...
🌐
LabEx
labex.io › tutorials › python-how-to-manage-empty-string-inputs-438180
How to manage empty string inputs | LabEx
Python offers several approaches to detect empty string inputs: def detect_empty_string(input_string): ## Method 1: Length Check if len(input_string) == 0: print("Empty string detected (length method)") ## Method 2: Boolean Evaluation if not ...
🌐
GitHub
github.com › PySimpleGUI › PySimpleGUI › issues › 4237
[Question] How can I check if an Input Box is empty before pressing a button? · Issue #4237 · PySimpleGUI/PySimpleGUI
April 30, 2021 - no, sparsely Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)? These items may solve your problem. Please check those you've done by changing - [ ] to - [X] Searched main docs for your problem www.PySimpleGUI.org · Looked for Demo Programs that are similar to your goal Demos.PySimpleGUI.org · If not tkinter - looked for Demo Programs for specific port
Published   Apr 30, 2021
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 381248 › using-try-except-to-catch-a-blank-input
python - Using Try, Except to catch a blank input [SOLVED] | DaniWeb
In python 3, after result = ... world " # another string, with white space at the end · result.strip() is the string with white space removed at both ends, so if there was nothing significant in the user's input, it's the ...
🌐
Scaler
scaler.com › home › topics › program to check if string is empty in python
Program to Check if String is Empty in Python - Scaler Topics
January 11, 2023 - When we work with strings in Python we know that they are immutable and hence handling the strings while we perform operations becomes tricky. A string with spaces is referred to as an empty string having a non-zero size. With the below article, we shall understand how we can check if a string is an empty Python and explore the various methods with elaborate explanations of the code example.
🌐
PythonHow
pythonhow.com › how › check-if-a-string-is-empty
Here is how to check if a string is empty in Python
my_string = "" if len(my_string) == 0: print("String is empty.")Another alternative would be to use the bool() function. This will check if the string is empty or not, returning True if it's empty and False if it's not.
🌐
Reddit
reddit.com › r/learnpython › how do i make a loop if my input is "" empty?
How do I make a loop if my input is "" empty? : r/learnpython
September 19, 2016 - This is called a sentinal value, and Python's built-in iter function is really nice for this. Combining it with map for the conversion to int, we have this: for val in map(int, iter(input, '')): # Do stuff with val ... iter keeps calling the function you give it (in this case, input) and yields each return value, until that return value equals the sentinal (here, the empty string), when iter stops
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-check-if-a-string-is-empty-or-contains-whitespaces-in-python
How to Check If a String is Empty or Contains Whitespaces in Python - GeeksforGeeks
July 23, 2025 - Sometimes, we must check if a string is empty or only contains Whitespaces. This check is useful when we are processing user input or handling data. Another simple way to check if a string is empty is by using the len() function.
🌐
Studytonight
studytonight.com › post › how-to-check-for-an-empty-string
How to check if string is empty in Python? - Studytonight
May 3, 2023 - It is denoted by two quotes with nothing in between them: "". You can check if a string is empty in Python using the not operator, which returns True if the string is empty and False otherwise.