How to Declare a Variable in Python?
The concept of constants and variables is something that we are studying right from our primary classes. We know that constants are the fixed values whereas variables are those whose values can be changed or varied.
In this article, we will discuss how to declare a variable in python.
Declaring a variable in Python programming language is a demonstration of the steps that we discuss in the algorithms.
They are the containers that can hold values of any datatype and occupy a space in the memory.
Let us have a look at the naming convention of our variables that makes them an authentic one-
Following are the rules that we must take care of-
- The name of our variable can have an underscore ( _ ).
- The name of the variable should not contain any special character.
- The name of the variable should not be a keyword.
We will discuss the given examples that will help us to understand the different ways of declaring a variable.
- A simple assignment of values to variables.
- Assigning values to variables in the same line.
- Assigning a single value to three variables at a time.
Let us have a look at the first example where we have assigned an integer value, a float value, and a string value to the variables a,b, and c respectively.