Python will do its best to evaluate the "truthiness" of an expression when a boolean value is needed from that expression.

The rule for strings is that an empty string is considered False, a non-empty string is considered True. The same rule is imposed on other containers, so an empty dictionary or list is considered False, a dictionary or list with one or more entries is considered True.

The None object is also considered false.

A numerical value of 0 is considered false (although a string value of '0' is considered true).

All other expressions are considered True.

Details (including how user-defined types can specify truthiness) can be found here: http://docs.python.org/release/2.5.2/lib/truth.html.

Answer from Larry Lustig on Stack Overflow
🌐
Astral
docs.astral.sh › ruff › rules › compare-to-empty-string
compare-to-empty-string (PLC1901) | Ruff
An empty string is falsy, so it is unnecessary to compare it to "". If the value can be something else Python considers falsy, such as None, 0, or another empty container, then the code is not equivalent.
Discussions

python - Empty String Boolean Logic - Stack Overflow
In python '==' tests for equality. The empty string is not equal to True, so the result of your comparison is False. More on stackoverflow.com
🌐 stackoverflow.com
How to check if the string is empty in Python? - Stack Overflow
Does Python have something like an empty string variable where you can do: ... Regardless, what's the most elegant way to check for empty string values? I find hard coding "" every time for checking an empty string not as good. ... None won't match "". So depends on the context as to what you want. wheredidthatnamecomefrom – wheredidthatnamecomefrom · 2022-07-09 17:05:23 +00:00 Commented Jul 9, 2022 at 17:05 ... Empty strings are "falsy... More on stackoverflow.com
🌐 stackoverflow.com
Why does my empty dictionary not evaluate to false?
Because an empty dictionary is not equal to false. In a boolean context, it's falsey (treated as false), but that's different from it literally comparing as the same as false. I keep thinking if a list or dictionary is empty it automatically evaluates to none. No, it's just equal to an empty list/dictionary. It will only evaluate to None if you use it in an expression like: {} or None # None More on reddit.com
🌐 r/learnpython
8
2
December 21, 2022
Help with understanding “Truthy” and “Falsey” values.
The empty string does not equal False. But the empty string will coerce to False if used in a boolean context. >>> '' == False False >>> bool('') False >>> not '' True More on reddit.com
🌐 r/learnpython
27
17
March 10, 2017
🌐
Reddit
reddit.com › r/learnpython › help with understanding “truthy” and “falsey” values.
r/learnpython on Reddit: Help with understanding “Truthy” and “Falsey” values.
March 10, 2017 -

I’m working through Automate the Boring Stuff and am having trouble understanding the "while not" bit in this piece of sample code:

name = ''
while not name:
    print('Enter your name:')
    name = input()

So far the other examples in the book have been "while True:", which makes sense to me.

If the code is changed to:

name = False
while name == False:
    print('Enter your name:')
    name = input()

The program will proceed if nothing is entered for name, whereas when using "while not name" the program will continue to ask for input for name.

If I change it again to:

name = False
while not name:
    print('Enter your name:')
    name = input()

I get the same results as the first piece of code.

My questions are twofold:

  1. How does while not work?

  2. Why would one choose to define the name variable as '' instead of False?

Edited to fix formatting.

🌐
Sololearn
sololearn.com › en › Discuss › 1779570 › is-an-empty-string-true-or-false-in-python-3
Is an empty string true or false in python 3 | Sololearn: Learn to code for FREE!
April 29, 2019 - It has a boolean value which can be found out with bool(''). But an empty string is not equivalent to False. If it were the same, an expression like if 5-5=='' would evaluate to True.
🌐
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 - The len() function returns the length of a string so if the length is 0, it means that string is empty: ... The string is empty. ... If len(s) == 0 then the string is empty. In Python, empty strings are treated as "Falsy".
🌐
Execute Program
executeprogram.com › courses › python-for-programmers › lessons › truthiness
Truthiness Lesson - Python for Programmers
Learn programming languages like TypeScript, Python, JavaScript, SQL, and regular expressions. Interactive with real code examples.
Find elsewhere
🌐
Inspired Python
inspiredpython.com › article › truthy-and-falsy-gotchas
Truthy and Falsy Gotchas • Inspired Python
For example: the number zero, empty strings and lists evaluate to False; but non-zero numbers, non-empty lists and lists are True. In this example Python knows that items is a list and that it is truthy if it contains at least one item, and ...
🌐
Hacker News
news.ycombinator.com › item
How about this: The empty string and 0 are truthy. Why? | Hacker News
July 6, 2020 - Lua, both has a dedicated nil value and a boolean type, so there's no reason whatsoever to treat zero as falsey, other than the C cargocult · As for empty strings, I really don't see the rationale behind it. An empty string is not nothing. At the very least, it still holds the length-data ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › check if string is empty or not in python
Check if String is Empty or Not in Python - Spark By {Examples}
May 21, 2024 - In this article, you have learned different ways to check if the string is empty or not in Python. Since empty strings are considered as false in Python, we can directly use it on the if condition to check or use it with either not operator ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Glossary › Falsy
Falsy - Glossary | MDN
July 11, 2025 - if (false) { // Not reachable } if (null) { // Not reachable } if (undefined) { // Not reachable } if (0) { // Not reachable } if (-0) { // Not reachable } if (0n) { // Not reachable } if (NaN) { // Not reachable } if ("") { // Not reachable } If the first object is falsy, it returns that object:
🌐
Esri Community
community.esri.com › t5 › python-questions › quot-if-not-null-and-not-empty-string-quot-paradox › td-p › 1618009
Solved: "If not Null and not empty string" paradox - help ... - Esri Community
May 29, 2025 - Empty string and None both evaluate to False so you can just say `if not` and it'll work. Your original logic is also evaluating to True if the sate is both None and not an empty string (which is always True) ... From both a practice ( https://peps.python.org/pep-0008/ ) and performance ...
🌐
Wyzant
wyzant.com › resources › ask an expert
Most elegant way to check if the string is empty in Python? | Wyzant Ask An Expert
May 22, 2019 - The empty string is the only possible zero-length string. All other strings return True. An if statement in Python must have a Boolean argument. So you don't have to write "if bool(myString)". "if myString" is syntactic sugar for calling bool(myString). Also, you don't have to explicitly write ...
🌐
Enterprise DNA
blog.enterprisedna.co › python-empty-string
Python Empty String: Explained With Examples – Master Data Skills + AI
The is_empty variable will now be a list of boolean values. If a value returns True, it’s an empty string. If it returns False, it is a non-empty string.
🌐
Stack Abuse
stackabuse.com › how-to-check-if-a-string-is-empty-or-none-in-python
How to Check if a String is Empty or None in Python
June 5, 2023 - Advice: Find out more about the or operator in Python by reading our "Guide to the Python or Operator". In this example, the if statement checks two conditions: if s is None and if s is an empty string. If either condition is true, it will print "String is empty or None". If both conditions are false (meaning the string is not None and it's not empty), it will print "String is not empty and not None".