Data Type - NoneType for Nothing

This section describes the NoneType data type, which only has a single object, the null object.

What Is the "NoneType"? "NoneType", also called "None", is the most simplest data type in Python. It has a single object, the null object, representing nothing. And it has with the following features:

1. The null object can be referred by the keyword, None, in Python code.

2. The null object is implicitly casted to True in a Boolean context.

>>> if None:
...     print("Yes")
... else:
...     print("No")

3. The null object is commonly used as the return value from functions/methods where nothing needs to be returned.

>>> l = ["apple", "banana", "cherry"]
>>> res = l.append("orange")
>>> l
['apple', 'banana', 'cherry', 'orange']

>>> type(res)
<class 'NoneType'>

4. The null object is actually stored in memory, with an identifier and some storage space:

>>> id(None)

>>> import sys
>>> sys.getsizeof(None)

5. The only operations you can perform in the null object is == and != with any objects of any type. The null object is not equal to any other non-null objects:

>>> None == None
>>> None != None

>>> None == 0
>>> None != 0

>>> None == False
>>> None != False

>>> None == []
>>> None == ()
>>> None == {}

Table of Contents

 About This Book

 Running Python Code Online

 Python on macOS Computers

 Python on Linux Computers

Built-in Data Types

 Introduction to Data Type

 Common Features of All Data Types

Data Type - NoneType for Nothing

 Data Type - 'bool' for Boolean Values

 Data Type - 'int' for Integer Values

 Data Type - 'float' for Real Numbers

 Data Type - 'bytes' for Byte Sequence

 Data Type - 'str' for Character String

 Data Type - 'tuple' for Immutable List

 Data Type - 'list' for Mutable List

 Data Type - 'dict' for Dictionary Table

 Variables, Operations and Expressions

 Statements - Execution Units

 Function Statement and Function Call

 Iterators, Generators and List Comprehensions

 Classes and Instances

 Modules and Module Files

 Packages and Package Directories

 "sys" and "os" Modules

 "pathlib" - Object-Oriented Filesystem Paths

 "pip" - Package Installer for Python - Python Libraries for Science

 pandas - Data Analysis and Manipulation

 Anaconda - Python Environment Manager

 Jupyter Notebook and JupyterLab


 Full Version in PDF/EPUB