Python | Declare any variable without assigning any value

Here, we will learn how to declare any variable without assigning any value in Python? By IncludeHelp Last updated : April 13, 2023

Declare any variable without assigning any value

Since, Python is a dynamic programming language so there is no need to declare such type of variable, it automatically declares when first time value assign in it.

Still, this is a common question asked by many programmers that can we declare any variable without any value?

The answer is: "Yes! We can declare such type of variable". To declare a variable without any variable, just assign None.

Syntax

variable_name = None

The following code shows the declaration of variable assigned with None:

num = None

Let's understand through a program.

Example to declare any variable without assigning any value in Python

# Python program to declare a
# variable without assigning any value

# declare variable
num = None

# print the value
print("value of num: ", num)

# checking variable
if num == None:
    print("Nothing")
else:
    print("Something")

# assign some value
num = 100

# print the value
print("value of num: ", num)

# checking variable
if num == None:
    print("Nothing")
else:
    print("Something")

Output

value of num:  None
Nothing
value of num:  100
Something

Python Basic Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.