codescracker


python

Python Variables



« Previous Tutorial Next Tutorial »


Variables in Python, are the reserved memory locations to store the values in a Python program. It means that, whenever you are creating a variable in Python programming, you are reserving some space in the memory for that variable.

Python Variables Example

Based on variable's data type, python interpreter allocates the memory and decides what can be stored in the reserved memory. Here is an example assigning values to the variables in Python:

# Python Variables - Example Program

num1=10
num2=20
sum=num1+num2

print(sum)

Here is the sample output of the above Python program:

python variables

Here is one more example program, uses three variables in python namely m, n, and r

# Python Variables - Example Program

m=54
n=45
r=0

r=m+n
print("sum = ", r)
r=m-n
print("Subtract = ", r)
r=m*n
print("Multiply = ", r)
r=m/n
print("Divide = ", r)

Here is the output produced by the above Python program:

variables in python example

More Examples

Here are the list of some more examples, uses variables in python:


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test