Skip to content

Python null string | Understanding string “null”

  • by

A non-empty string is always True in python. So “null” evaluates to True in a boolean operation, just as “Apple”.

In Python, there is no null keyword or object available. Instead, you may use the ‘None’ keyword, which is an object.

Example null string Python

"" is an empty string, "null" is not:

print(bool(""))
print(bool("null"))

Output:

Python null string

How to declare a null string in python?

The equivalent of the null keyword in Python is None.

str1 = None
print(str1)
print(type(str1))

Output:

How to declare a null string in python

Do comment if you have any doubts and suggestions on this Python string topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading