Q:

Python | Declare any variable without assigning any value

0

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

Example:

 num = None

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Let’s understand through a program:

# 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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now