GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • CODESCRACKER
  • Python
  • Java
  • C++
  • JavaScript
  • SQL
  • Quiz
  • C
  • C#
  • HTML
  • CSS
  • PHP
  • Networking
  • Operating System

This view

  • Original page
  • New address

GeezerVison is showing codescracker.com — Python None Keyword

  • Python Basics
  • Python Tutorial
  • Python Applications
  • Python Versions
  • Python environment setup
  • Python Basic Syntax
  • Python end (end=)
  • Python sep (sep=)
  • Python Comments
  • Python Identifiers
  • Python Variables
  • Python Operators
  • Python Ternary Operator
  • Python Operator Precedence
  • Python Control and Decision
  • Python Decision Making
  • Python if elif else
  • Python Loops
  • Python for Loop
  • Python while Loop
  • Python break Statement
  • Python continue Statement
  • Python pass Statement
  • Python break vs. continue
  • Python pass vs. continue
  • Python Built-in Types
  • Python Data Types
  • Python Lists
  • Python Tuples
  • Python Sets
  • Python frozenset
  • Python Dictionary
  • List vs. Tuple vs. Dict vs. Set
  • Python Numbers
  • Python Strings
  • Python bytes
  • Python bytearray
  • Python memoryview
  • Python Misc Topics
  • Python Functions
  • Python Variable Scope
  • Python Enumeration
  • Python import Statement
  • Python Modules
  • Python operator Module
  • Python os Module
  • Python Date and Time
  • Python Exception Handling
  • Python File Handling
  • Python Advanced
  • Python Classes and Objects
  • Python @classmethod Decorator
  • Python @staticmethod Decorator
  • Python Class vs. Static Method
  • Python @property Decorator
  • Python Keywords
  • Python Keywords
  • Python and
  • Python or
  • Python not
  • Python True
  • Python False
  • Python None
  • Python in
  • Python is
  • Python as
  • Python with
  • Python yield
  • Python return
  • Python del
  • Python from
  • Python lambda
  • Python assert
  • Python Built-in Functions
  • Python All Built-in Functions
  • Python print() Function
  • Python input() Function
  • Python int() Function
  • Python len() Function
  • Python range() Function
  • Python str() Function
  • Python ord() Function
  • Python chr() Function
  • Python read()
  • Python write()
  • Python open()
  • Python Examples
  • Python Examples

Python None Keyword

The "None" keyword in Python is used when we need to declare a variable with no value at all. The interesting thing about the None keyword is that it is a constant value with no value at all.

"None" is neither a 0 nor an empty string like "". That is, "None" is none, nothing else. For example:

a = None
b = 0
c = ""
print(type(a))
print(type(b))
print(type(c))

The output is:

<class 'NoneType'>
<class 'int'>
<class 'str'>

It means that, like 0 is of the "int" type, "" is of the "str" type. Similarly, "None" is of the "NoneType" value.

Note: Python is a case-sensitive language; therefore, keep the first letter of the None keyword in capital letters, and the remaining 3 letters must be in small letters.

Python None Keyword Example

Here is an example of the None keyword in Python. This program demonstrates that a function with no return value will return None.

def funOne():
    x = 10

def funTwo():
    x = 100
    return x

x = funOne()
print(x)

x = funTwo()
print(x)

The output is:

None
100

Advantages of the None keyword in Python

Following is a list of some of the advantages of the "None" keyword in Python.

  • "None" can be used as a function's default argument value to show that the user didn't give any arguments.
  • When defining a variable that will be given a value later, "none" can be used as a placeholder value.
  • Before a value is given to a variable, it can be set to "none" to get it ready.
  • "None" can be used to show that an iterator in a loop has reached its end.

Disadvantages of the None keyword in Python

Following is a list of some of the disadvantages of the "None" keyword in Python.

  • "None" is a special value, so it can't be used everywhere where a value is needed. For instance, it can't be used as a dictionary key because dictionary keys have to be unchangeable and "None" isn't.
  • Using "None" as the default value for an argument in a function can lead to unexpected results if the argument is mutable and the function changes it. In these situations, it's best to use a different default value, like an empty list or dictionary.
  • If "None" is a valid value in the iterable being looped over, using "None" as a sentinel value can cause confusion and errors. It's best to use a sentinel value that is unique and can't be found in the iterable.

Python Online Test


« Previous Tutorial Next Tutorial »
Practice Quizzes

Test your programming and computer science knowledge with interactive MCQs and topic-based quizzes.

All Quizzes SQL Quiz Python Quiz Java Quiz C++ Quiz
Popular Topics

Explore the most popular programming and computer science tutorials on CodesCracker.

Python Tutorial Java Tutorial C++ Tutorial SQL Tutorial JavaScript Tutorial HTML Tutorial CSS Tutorial Computer Networking
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.