Python Tutorials - Herong's Tutorial Examples - v2.15, by Herong Yang
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")
...
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) 4547296864 >>> import sys >>> sys.getsizeof(None) 16
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
True
>>> None != None
False
>>> None == 0
False
>>> None != 0
True
>>> None == False
False
>>> None != False
True
>>> None == []
False
>>> None == ()
False
>>> None == {}
False
Table of Contents
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 - 'set' for Unordered Collection
Data Type - 'dict' for Dictionary Table
Variables, Operations and Expressions
Function Statement and Function Call
List, Set and Dictionary Comprehensions
Packages and Package Directories
"pathlib" - Object-Oriented Filesystem Paths
"pip" - Package Installer for Python
SciPy.org - Python Libraries for Science
pandas - Data Analysis and Manipulation
Anaconda - Python Environment Manager