Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Python Foundations - Assessments

6 / 54

Variables in Python

In the previous exercise, we have seen Python is a great calculator. In real-life when we write code, we use variables to define values so that we can reuse them again and again in our code.

A variable is a name that refers to a value. Let's see some examples.

my_name = "John"
age = 28
pi = 3.14

Here John is a string which is assigned to my_name variable. Similarly 28 is a number which is assigned to variable age. Variable pi is assigned the value of 3.14

Pro Tip - = is an assignment operator in Python. You can assign a value to a variable using = operator

Display value of a variable

To print the value of a variable, we use print statement. To print the value of my_name and pi, simply type below statement into a Jupyter notebook on the right-hand side and execute the cells.

print(my_name)
print(pi)
INSTRUCTIONS

Use Jupyter notebook on the right-hand side to write code and complete this exercise

  • Define variable bank_balance with the value 200
  • Print value of bank_balance. It should print 200


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...