Check if String is Empty or Not - Python Last Updated : 12 Apr, 2025 Comments Improve Suggest changes Like Article Like Report We are given a string and our task is to check whether it is empty or not. For example, if the input is "", it should return True (indicating it's empty), and if the input is "hello", it should return False. Let's explore different methods of doing it with example:Using Comparison Operator(==)The simplest and most commonly used approach is using comparison operator(==): Python s = "" if s == "": print("The string is empty.") else: print("The string is not empty.") OutputThe string is empty. Explanation: A simple equality check (s == "") determines if the string is empty.Using len()The len() function returns the length of a string so if the length is 0, it means that string is empty: Python s = "" if len(s) == 0: print("The string is empty.") else: print("The string is not empty.") OutputThe string is empty. Explanation:len(s): calculates the length of s.If len(s) == 0 then the string is empty.Using Python's Truthy/Falsy BehaviorIn Python, empty strings are treated as "Falsy". So, we can use this for checking if a string is empty or not. Python s = "" if not s: print("The string is empty.") else: print("The string is not empty.") OutputThe 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. Comment More infoAdvertise with us Next Article Check if String is Empty or Not - Python M manjeet_04 Follow Improve Article Tags : Python Python Programs python-string Python string-programs Practice Tags : python Similar Reads Python | Check if any String is empty in list Sometimes, while working with Python, we can have a problem in which we need to check for perfection of data in list. One of parameter can be that each element in list is non-empty. Let's discuss if a list is perfect on this factor using certain methods. Method #1 : Using any() + len() The combinati 6 min read Python Check If String is Number In Python, there are different situations where we need to determine whether a given string is valid or not. Given a string, the task is to develop a Python program to check whether the string represents a valid number.Example: Using isdigit() MethodPython# Python code to check if string is numeric 6 min read Python Check if Nonetype or Empty In Python, it's common to check whether a variable is of NoneType or if a container, such as a list or string, is empty. Proper handling of such scenarios is crucial for writing robust and error-free code. In this article, we will explore various methods to check if a variable is either of NoneType 3 min read Check If a Python Set is Empty In Python, sets are versatile data structures used to store unique elements. It's common to need to check whether a set is empty in various programming scenariosPython# Initializing an empty set s = set() print(bool(s)) # False since the set is empty print(not bool(s)) # True since the set is empty 2 min read Check If Python Json Object is Empty Python users frequently work with JSON, particularly when exchanging data between multiple devices. In this article, we'll learn how to check if a JSON object is empty using Python. Check If a JSON Object Is Empty in PythonBelow, we provide examples to illustrate how to check if a JSON object is emp 3 min read Like