fb pixel

Variables in Python

In Python, information is stored in variables. We have already interacted with variables before when getting inputs from the user.
name = input()
surname = input()
print(name, '--', surname)
This program reads two inputs. It stores the first input in a variable called name and the second input in a variable called surname. In the case the person using the program inputs Nikola for the first input and then hit enter and put Tesla for the second input and then hit enter the name variable will store Nikola value in it and whenever printed will show Nikola, while surname variable will store Tesla value in it and whenever printed will show Tesla.
Variables can be used to store any type of information. They can store textual information as shown in the example above, they can store numbers, they can store collections, and other structures.
To store numeric values in variables we can do the following:
a = 10
b = 400
print(a, b, a * b)
The program will print 10 400 4000.
This program stores 10 in a variable called a, 400 in a variable called b, and then prints their values along with the multiple of those two.


Write a program that stores -20 in a variable called x, 30 in a variable called y, and 100 in a variable called z. Print the result of the x * y + z expression.
So, we can use Python to do basic arithmetic operations and use it as a simple calculator.
To check your solution you need to sign in
Sign in to continue