Home » Python » Python programs

Python program for not None test

Python example for None keyword: Here, we are going to learn how to check whether a variable contains a value or not?
Submitted by IncludeHelp, on April 07, 2019

As we have discussed in the previous post (Python None keyword), that "None" is a keyword which can be used to assign a null value to a variable or to check whether a variable contains any value or not.

Example:

Here, we have 3 variables a, b and c, a is being assigned with "Hello", b is being assigned with "None" and c is being assigned with 10.

We are testing whether variables have a value or None, if they have values, we are printing their values.

# python code for not None test

# variable 1 with value
a = "Hello"

# variable 2 with None
b = None

# variable 3 with value 
c = 10

# performing is not None test 
if a is not None:
    print("value of a: ", a)
else:
    print("\'a\' contains None")

if b is not None:
    print("value of b: ", b)    
else:
    print("\'b\' contains None")

if c is not None:
    print("value of c: ", c)
else:
    print("\'c\' contains None")

Output

value of a:  Hello
'b' contains None
value of c:  10





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.