Crus4

logo

What are Variables in Python

Intro to Python Variables
Table of Contents

Variables in Python allows us to store a data by assigning it to a name. Variables are used to hold values that can be referenced and manipulated in a program. Python is dynamically typed, meaning you don’t need to specify a variable’s data type when declaring.

To declare a Variables in Python, you simply assign a value to a name using the equals sign =. Here is an example:

Example

name = "John"
age = 20

In an above example, the variable name is assigned a string value of "John" and the variable age is assigned an integer value of 20.

Rules for Python Variable Names

Variable names in Python can only include letters, digits, and underscores, but cannot begin with a digit. Variable names must not include any special character like %, $ etc. Since Variable names are case sensitive, so age and Age are different variables.

Assign Multiple Values

Python supports multiple assignment, which allows you to assign values to multiple variables at once. For Example:

x, y, z = 1, 2, 3
print (x) #Outputs: 1
print (y) #Outputs: 2
print (z) #Outputs: 3

Python also allows us to assign the same value to multiple variales. For Example:

x, y, z = "Mango"
print (x) #Outputs: Mango
print (y) #Outputs: Mango
print (z) #Outputs: Mango

Share This Post!

What are Variables in Python