Book Image

Python Essentials

By : Steven F. Lott
Book Image

Python Essentials

By: Steven F. Lott

Overview of this book

Table of Contents (22 chapters)
Python Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

The None object


One very simple kind of Python object is the None object. It has few methods, and there's only a single instance of this object available. It is a handy way to identify something as missing or not applicable. It's often used as a default value for optional parameters to a function.

The None object is a singleton; there can be only one. This object is immutable: we can't change it in any way.

With the interactive use of Python, the REPL doesn't print the None object. For example, when we evaluate the print() function, the proper result of this function is always None. The side-effect of this function is to print things on our console. Looking forward to Chapter 3, Expressions and Output, we'll give this quick example of a function that returns None:

>>> a = print("hello world")
hello world
>>> a
>>> a is None
True

We've evaluated the print() function and saved the result of the print function in the a variable. The visible side-effect of printing is...