Python Variables

Python Variables are used to store some data or values in the program. These variables are actually reserved memory locations whose values can be changed later during program execution.

Unlike other programming languages, there is no need of extra keyword or command to declare the Python variables. The Syntax of Python variable is x = 123. Here, x is a variable name and it stores a number 123.


Example of Python Variables:

We can store different types of value in the variables such as integer, float, string, complex etc.

Let’s see a simple example to store some values. After that, we will display those variables using the print function.


Key points about Python Variables:

Here is the list of important points to remember while giving the name to the variables.

  1. We can’t use special characters anywhere in the name of variables, except underscore _.
  2. Space or Indents are not allowed in the variable naming such as var 1 is invalid variable.
  3. We can use digits (numbers) at the middle or at the end of the variable’s names. But digits are not allowed at the starting of the variable naming such as 12sum is invalid variable.
  4. We recommend to use meaning name for the variables so that it is easy to understand.

Example of valid numbers:

Example of invalid numbers:

Variable names in Python is case sensitive. So, using Salary, salary will be treated as two different variables.


Assigning multiple values to variables in a single line

We can assign multiple values in a single line to the different variables kike other programming languages. Let’s see a simple example of it.


Assigning same value to the multiple variables

We can also assign the same value to multiple variables. Let’s see a simple example now.


Printing multiple variables using single print statement

We can print multiple Python Variables using a single print statement. Here is a simple example.


Congratulations! Chapter Finished. Do you want to practice more?
Exercises & Assignments
  • No Content Found.
  • Interview FAQs
  • No Content Found.