Menu Close

How to check if the string is empty with Python?

Sometimes, we want to check if the string is empty with Python.

In this article, we’ll look at how to check if the string is empty with Python.

How to check if the string is empty with Python?

To check if the string is empty with Python, we can use the not operator.

For instance, we write

if not my_string:
  # ...

to check my_string is empty with if not my_string.

Empty strings are falsy so we can use not to check if the string is empty.

Conclusion

To check if the string is empty with Python, we can use the not operator.

Posted in Python, Python Answers