Home » Python

None keyword with example in Python

Python None keyword: Here, we are going to learn about the None keyword in Python with example.
Submitted by IncludeHelp, on April 07, 2019

Python None keyword

"None" is a keyword (case-sensitive), which is similar to null, it is used to define a null value to the variable or represents that a variable does not have any value at all.

None is a type of <class 'NoneType'>.

Syntax:

    None

Example:

    Input:
    a = None
    print("a: ", a);

    Output:
    a: None

Python code to demonstrate example of None keyword

# python code to demonstrate example of 
# None keyword

# type of None
print("type of None: ", type(None))

# declaring a variable and initialize it with None
a = None
# printing value
print("a: ", a)

# checkng None in condition
if a == None:
    print("variable \'a\' contains None")
else:
    print("variable \'a\' does not contain None")

# assigning a value and rechecking the condition
a = 100
if a == None:
    print("variable \'a\' contains None")
else:
    print("variable \'a\' does not contain None")

Output

type of None:  <class 'NoneType'>
a:  None
variable 'a' contains None
variable 'a' does not contain None





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.