In this tutorial we are going to learn about, how to check if a string is empty or not in Python.
To check if a string is empty or not, we can use the
if not statement in Python.
Note: Empty strings are treated as falsy values in Python.
Here is an example:
name = "" if not name: print("name is empty")
name is empty
Similarly, we can also use the
len() function in Python.
place = "" # checking if string is empty if len(place) == 0: print('String is empty') else: print('String is not empty')
String is empty