> For the complete documentation index, see [llms.txt](https://training.gitbook.io/python-documents/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://training.gitbook.io/python-documents/variables-in-python.md).

# Variables In Python

![](https://767344992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMiliykuSLaUcLgGbj1qR%2Fuploads%2FGQGR2X8plRIE0S6UCYvX%2Fimage.png?alt=media\&token=f4765bc4-c06c-4db1-89de-5fd6110fe3f9)

**What are Variables?**

Variables are a container that store temporary values or information in computer memory.To use a variable in program, you must declare a variable.

**What do we mean by declaring a Variable in python?**

In Python, the moment we store any information or value in a variable, variable is declared.We can use variables in program once we declare them or store a value in them. There are two most important entity to declare a variable:\
a. Variable name\
b. Value

For Example : age = 10, Here 10 is a value stored in variable named age. This is how we declare a Variable in Python.

In \[1]:

```
age = 10
print(age)
```

```
10
```

**Naming Convention in Variable:**

There are some rules and best practices to follow while naming a variable:

**Best Practice**: While naming a variable, Keep in mind to give variables a meaningful name. a = 10 does not give clear message than age = 10

Rules: 1.Variables are Case-Sensitive. It means a variable with lowercase is different than the variable in upper case.

In \[2]:

```
age = 10
Age = 20
AGE = 30
print(age,Age,AGE)
```

```
10 20 30
```

2.We cannot name a variable starting with a number . `1age = 10` will give error.

In \[3]:

```
1age = 20
```

```
  File "<ipython-input-3-ef3a9e7a157c>", line 1
    1age = 20
     ^
SyntaxError: invalid syntax
```

3.We cannot use whitespaces or any symbol while naming a variable , though underscore is allowed (\_). For Example -

* a ge = 10 , @%age=10 will give error
* \_age = 10 , voting\_age = 18 is good.

In \[1]:

```
_company = "Console Flare"
company_name = "ConsoleFlare"
print(_company,company_name)
```

```
Console Flare ConsoleFlare
```

**How to assign or store multiple values in multiple variables:**

To assign multiple values in multiple variables , we can simply write them in a single line of code using commas. For Example:

In \[2]:

```
company , company_member = "Console Flare",5000
print(company,company_member)
```

```
Console Flare 5000
```

**How to assign a single Value in multiple Variable:**

To assign a single value in multiple variables , we can simply write them in a single line of code using = sign. For Example:

In \[3]:

```
company = firm = startup = "Console flare"
print(company,firm,startup)
```

```
Console flare Console flare Console flare
```

**How to change a value of a variable:**

Suppose there is a variable named age with value 10 , we will write it like this (age = 10) to change the value of variable we will again store another value to the same variable. for Example:

In \[4]:

```
age = 10
print(age)
age = 20
print(age)
```

```
10
20
```

## Assignment:

* Create a variable and store any numerical value.
* Change the value stored in a variable.
* Store 10,20,30 in three different variables in a single line.
* Store 10 in three different variables in a single line.

![](https://767344992-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FMiliykuSLaUcLgGbj1qR%2Fuploads%2FcGhWnm6Pt3M89z8qvEWa%2Fimage.png?alt=media\&token=f96c28dd-9efe-4bf2-8f4e-8daf38f5837d)
