Python Basics

Variables & Data Types

Foundation concepts of Python programming — learn how to store and work with data effectively.

Python 3 ✓ Beginner Friendly 2 Topics
01

Variables in Python

A variable is a name used to store data in memory. Python is dynamically typed and case-sensitive: age, Age, and AGE are three different variables.

Python — Variables
# Creating variables — just assign a value
x = 10
name = "Alice"
is_student = True

# Case sensitivity demo
age = 20
Age = 30
print(age)   # 20
print(Age)   # 30

# Updating a variable
count = 1
count = 2   # value updated
Naming Rules
✓ Valid Names
  • total_marks
  • student_name
  • _count
  • value2
✗ Invalid Names
  • 2marks — starts with number
  • total-marks — contains hyphen
  • for — Python keyword
02

Data Types in Python

TypeKeywordExampleUsed For
Integerintage = 25Counting, indexing, loops
Floatfloatpi = 3.14Measurements, prices
Stringstrname = "Alice"Text, names, messages
Booleanboolflag = TrueConditions, loops
NoneNoneTyperesult = NoneNo value / empty state
Complexcomplexz = 3 + 4jScientific calculations
Type Conversion Rules: Allowed: int→float, int→complex, float→complex, int→str. NOT allowed: complex→int or complex→float directly (use int(z.real) instead).

Quick Quiz

1. Which of these is mutable in Python?
2. What does type(3.14) return?
3. Which value is falsy?
4. Valid f-string syntax?
5. What is None's type?