+ 6
What is the meaning of None in python?
3 Answers
+ 11
This is used to represent a variable that has no value or type to it.
Even though var = 0 or var = "" may look like a representation of nothing, they still are something.
var = 0 is still an integer (which is zero)
var = "" is still a string (just a blank one)
var = None however has no type. It's not an integer, float, string, or anything (It's officially called a "NoneType").
+ 4
Robert explained it perfect. But You can do a test in python console:
1) Test for string:
a = " "
if a == None:
print('It is None')
else:
print('It is NOT NONE, I am still string, but empty')
2) Test for int:
b = 0
if b == None:
print('Im None')
else:
print('Im int and I have a value 0!')
3) test with type() function, example:
list = []
str = "abc"
n = 0
nothing = None
print(type(list))
print(type(str))
print(type(n))
print(type(nothing))
+ 1
None is similar to null which we use in most of the programming languages.