Python : What is None in python ;-)

Python’s None is Null of of Java, php, javascript of other programing language.

The concept of a null keyword is that it gives a variable a neutral, or “null” behaviour.

Python’s null Equivalent: None

The equivalent of the null keyword in Python is None. It was designed this way for two reasons:

  • Many would argue that the word “null” is somewhat esoteric. It’s not exactly the most friendliest word to programming novices. Also, “None” refers exactly to the intended functionality – it is nothing, and has no behaviour.
  • In most object-oriented languages, the naming of objects tend to use camel-case syntax. eg. ThisIsMyObject. As you’ll see soon, Python’s None type is an object, and behaves as one.

Checking if a Variable is None

There are two ways to check if a variable is None. One way can be performed by using the is keyword. Another is using the == syntax. Both comparison methods are different, and you’ll see why later:

null_variable is None
not_null_variable is not None
null_variable is None
not_null_variable is not None

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s