How to Declare a Variable Without Assigning it a Value in Python [5 Ways]

In this Python post, I will describe how to declare a variable without assigning it a value in Python. I will also cover several ways to declare a variable without assigning it a value like by using the None, storing variables in different empty datatypes.

While working with variables in Python, sometimes it makes sense to initialize a variable but not assign it any value. Sometimes, this can be any keyword as a reference or sometimes empty datatypes.

Now, let’s look at each of these examples in detail below.

Declare a variable without assigning it a value in Python using None

In Python, to declare a variable without assigning it a value, set it to None. The None keyword in Python is used to define variables that store a null or not accessible value.

This is the full code of Python to declare a variable without assigning it a value using None.

USA_coordinates = None
print(USA_coordinates)

Output:

None

You can refer to the below image to see the output of the Python program to declare a variable without assigning it a value using None.

How to Declaring a Variable Without Assigning it a Value in Python

Python program to declare a variable without assigning it a value with an empty list

If you need to declare a variable of list type, declare an empty list. An empty list in Python does not store any elements. However, it still enables you to call list-specific methods.

READ:  How to convert a list to DataFrame in Python [9 ways]

This is Python’s source code to declare a variable without assigning it a value with an empty list.

Texas_population = []

print(Texas_population)
print(type(Texas_population))

Output:

[]
<class 'list'>

Refer to the screenshot below to see the output of the Python program to declare a variable without assigning it a value with an empty list.

Declare a variable without assigning it a value with empty list in Python

How to declare a variable without assigning it a value with an empty dictionary in Python

In Python, a dictionary is a mapping of key-value pairs. If you need to declare an empty dictionary, use an empty set of curly braces {}.

Here is the complete Python program to declare a variable without assigning it a value with an empty dictionary.

cities = {}

print(cities) 

print(type(cities))

Output:

{}
<class 'dict'>

The screenshot below shows the output of the Python program to declare a variable without assigning it a value with an empty dictionary.

Python program to declare a variable without assigning it a value with an empty dictionary

Python program to declare a variable without assigning it a value with an empty set

This is another way to declare a variable without assigning it a value with an empty set. In Python, a set object is an unordered collection of unique elements.

Below is the Python program to declare a variable without assigning it a value with an empty set.

car_brands = set()

print(car_brands)
print(type(car_brands))

Output:

set()
<class 'set'>

You can see the output of the Python program to declare a variable without assigning it a value with an empty set.

How to declare a variable without assigning it a value with an empty set

Declare a variable without assigning it value with an empty tuple() class

In Python, the tuple is an ordered, immutable collection of elements. I will use the tuple() class to achieve the result in this approach.

This is the full code of Python to declare a variable without assigning it a value with an empty tuple() class.

my_variable = tuple()

print(my_variable) 
print(type(my_variable))

Output:

()
<class 'tuple'>

Refer to the screenshot below to see the output of the Python program to declare a variable without assigning it a value with an empty tuple() class.

Declare a variable without assigning it a value with an empty tuple() class in Python

Conclusion

I hope you like this article. Here, I have covered how to declare a variable without assigning it a value in Python with different approaches and descriptive examples.

READ:  Python Check if a variable is a number

I have explained various ways to declare a variable without assigning it a value in Python, such as using None, with an empty list, empty dictionary, empty set() class, and empty tuple() class.

Every approach has advantages and use cases; choose according to your requirements.

You may also like to read: