Language

Python Basics · Lesson 2 of 56

Variables

Source: 1-Python Basics/1.1-Variables.ipynb

Start here — no coding background needed

What you will learn

Store information in named boxes (variables) and use them later.

In simple words

A variable is a label on a box. You put a value inside — a name, number, or yes/no — and reuse it by the label name.

Think of it like this

Sticky notes: one says `age = 25`, later you read the note instead of rewriting 25 everywhere.

How to use this lesson

  1. Run the example
  2. Change name and age
  3. Add a third print combining both

Words to know:

  • Variable — A named place to store a value
  • = — Puts a value into the variable (not math "equals" here)

Start here if you have never coded. We use everyday examples — no jargon without explanation.

Easy example — try this first

Easy example — run this first. Change values and press Run again.

Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference notes (from full bootcamp)

Optional — deeper detail for when you are ready

Variables

Variables are fundamental elements in programming used to store data that can be referenced and manipulated in a program. In Python, variables are created when you assign a value to them, and they do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable.

Video Outline:

  • Introduction to Variables
  • Declaring and Assigning Variables
  • Naming Conventions
  • Understanding Variable Types
  • Type Checking and Conversion
  • Dynamic Typing
  • Practical Examples and Common Errors
Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
age : 32
Height: 6.1
Name: Anshul

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
False

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
<class 'str'>

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
float

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
<class 'int'>
25
<class 'str'>

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
<class 'int'>

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
float

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
5.0

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
10 <class 'int'>
Hello <class 'str'>
3.14 <class 'float'>

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Example HCL
HCL
## input

age=int(input("What is the age"))
print(age,type(age))

Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).

Example HCL
HCL
### Simple calculator
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

sum = num1 + num2
difference = num1 - num2
product = num1 * num2
quotient = num1 / num2

print("Sum:", sum)
print("Difference:", difference)
print("Product:", product)
print("Quotient:", quotient)

Browser practice only — full example needs Python on your computer (files, Flask, threads, etc.).

Conclusion:

Variables are essential in Python programming for storing and manipulating data. Understanding how to declare, assign, and use variables effectively is crucial for writing functional and efficient code. Following proper naming conventions and understanding variable types will help in maintaining readability and consistency in your code.

Practice test — try yourself

Write code, press Check. Wrong answer shows the correct code to copy & run.

Create name = "Anshul" and age = 22, then print: Name: Anshul and Age: 22 (use your variables).

Hint: print("Name:", name)

Python