Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
How to convert Nonetype to int or string?
Next article icon

How to check NoneType in Python

Last Updated : 24 Jan, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The NoneType object is a special type in Python that represents the absence of a value. In other words, NoneType is the type for the None object, which is an object that contains no value or defines a null value. It is used to indicate that a variable or expression does not have a value or has an undefined value. "None" basically means the absence of a value.

In this article, we are going to discuss methods for how to check NoneType in Python along with proper steps and outputs.

Check NoneType in Python

Below are some ways by which we can check the NoneType in Python:

  • Using is operator
  • Using Assignment Operator
  • Using type() Method
  • Using if Condition

Python Check NoneType Using 'is' Operator

In this example, the is operator is used to check whether a variable is of None type. If the x is None, then it will print x along with its type as shown in the output, else it will print the else statement "X is not None".

Python3
x = None  if x is None:     print(x)     print(type(x)) else:     print("X is not None") 

Output
None <class 'NoneType'>

Python Check None Using Assignment Operator (==)

In this example, the code checks if the variable x is equal to None using the equality (==) operator and prints a corresponding message. If x is None, it prints "The result is None"; otherwise, it prints "The result is not None."

Python3
x = None  # using assignment operator if x==None:     print(&quot;The result is None&quot;) else:     print(&quot;The result is not None&quot;) 

Output
The result is None

Check Python None Type Using type() Method

In this example, the code employs the type() method to check if the variable x is of type NoneType. It prints "The variable is of NoneType." if x is None; otherwise, it prints "The variable is not of NoneType."

Python3
x = None  # Using type() method if type(x)==type(None):     print(&quot;The variable is of NoneType.&quot;) else:     print(&quot;The variable is not of NoneType.&quot;) 

Output
The variable is of NoneType.

Check Python None Using if Condition

In this example, the code uses an if condition with the value None, which is considered as False in a boolean context. Therefore, it executes the else block and prints the value which is 10.

Python3
# Using if condition if None:   print(0) else:   print(10) 

Output
10

Next Article
How to convert Nonetype to int or string?
author
aryangfg2207
Improve
Article Tags :
  • Python
  • Python Programs
  • Geeks Premier League
  • Geeks Premier League 2023
Practice Tags :
  • python

Similar Reads

  • Python Check if Nonetype or Empty
    In Python, it's common to check whether a variable is of NoneType or if a container, such as a list or string, is empty. Proper handling of such scenarios is crucial for writing robust and error-free code. In this article, we will explore various methods to check if a variable is either of NoneType
    3 min read
  • Python | Check for None Tuple
    Sometimes, while working with Python records, we can have a problem in which we need to filter out all the tuples which contain just None values. This can have a possible application in Data Science domain. Let's discuss certain ways in which this task can be performed. Method #1 : Using all() + gen
    6 min read
  • How to convert Nonetype to int or string?
    Sometimes, Nonetype is not preferred to be used in the code while in production and development. So, we generally convert None to string or int so that we can perform favorable operations. In this article, we will learn about how to convert Nonetype to int or string in Python. Table of Content Conve
    3 min read
  • Python - Check for None value in Matrix
    Python supports a list as its list element and hence a matrix can be formed. Sometimes we might have a utility in which we require to perform None check in that list of list i.e matrix and its a very common in all the domains of coding, especially Data Science. Let’s discuss certain ways in which th
    5 min read
  • How to Check if Tuple is empty in Python ?
    A Tuple is an immutable sequence, often used for grouping data. You need to check if a tuple is empty before performing operations. Checking if a tuple is empty is straightforward and can be done in multiple ways. Using the built-in len() will return the number of elements in a tuple and if the tupl
    2 min read
  • Python | Check if tuple has any None value
    Sometimes, while working with Python, we can have a problem in which we have a record and we need to check if it contains all valid values i.e has any None value. This kind of problem is common in data preprocessing steps. Let's discuss certain ways in which this task can be performed. Method #1 : U
    5 min read
  • Python | Check for Whitespace in List
    Sometimes, we might have a problem in which we need to check if the List of strings has any of blank spaces. This kind of problem can be in Machine Learning domain to get specific type of data set. Let’s discuss certain ways in which this kind of problem can be solved. Method #1: Using regex + any()
    4 min read
  • Python Check If String is Number
    In Python, there are different situations where we need to determine whether a given string is valid or not. Given a string, the task is to develop a Python program to check whether the string represents a valid number. Example: Using isdigit() Method [GFGTABS] Python # Python code to check if strin
    6 min read
  • How To Check If Variable Is Empty In Python?
    Handling empty variables is a common task in programming, and Python provides several approaches to determine if a variable is empty. Whether you are working with strings, lists, or any other data type, understanding these methods can help you write more robust and readable code. In this article, we
    3 min read
  • Check if String is Empty or Not - Python
    We are given a string and our task is to check whether it is empty or not. For example, if the input is "", it should return True (indicating it's empty), and if the input is "hello", it should return False. Let's explore different methods of doing it with example: Using Comparison Operator(==)The s
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences