What is NoneType in Python and Null Equivalent?
NoneType in Python is the data type of the object when the object does not have any value. You can initiate the
NoneType object using keyword
None as follows.
obj = None
Let’s check the type of object variable ‘obj’.
obj = None type(obj)
NoneType object indicates no value.
If you try to print the value of the
NoneType object, it does not print anything on Python interpreter console.
When is NoneType used?
It is useful in many places.
It is default return type of the function when the function does not return any value.
Use cases (Examples):
- If the regular expression in re.search does not match, it returns
- When you search key in the diction and key is not present, it returns
Nonekeyword is also used for matching or to identify certain functions return any value or not.
What is Equivalent to NULL in Python?
You might have seen NULL value in many of the programming languages but Python. In, PHP, the null value is represented as
NULL. In Java programming, it is represented with keyword
In Python, there is no keyword NULL. Here None keyword is used as equivalent to the NULL.
If you are moving from other programming languages to Python, don’t get confused with
None keyword or
NoneType object in Python.
For more about Python, do check complete Python tutorial.