Ask coding questions

← Back to all posts
How do I set a variable to nothing?
xMysticalCoder (2)

Im trying to make a Encoder in python as my first project, and when ever I type:

randomVar =

It gives me a error, instead of a blank variable.

Does anyone know how to set a variable to nothing?

Answered by ANDREWVOSS (36) [earned 5 cycles]
View Answer
Comments
hotnewtop
ANDREWVOSS (36)

You can't create an empty variable in Python, but you can do

randomVar = None
RYANTADIPARTHI (6006)

Solution

the None keyword is useful here.

variable = None

there.

IntellectualGuy (668)

There is a data type in python, called NoneType, here's how you would declare it

VarName = None
Trex10 (7)

Yeah python doesn't let you set a variable to nothing by saying (the variable name) =
But you can set it to None like the other post says, or you can just set it to something random until you need to change it.