Python Introduction & Fundamentals
Welcome to Python! Learn what makes Python so popular, master the fundamentals, and build a strong foundation with practical examples.
What is Python?
High-level, interpreted programming language created by Guido van Rossum in 1991
Most Popular
Used by beginners and experts in data science, AI, web dev, and more
Simple & Clean
Readable syntax that looks like English, perfect for beginners
1. Python Variables
A variable is a name that stores a value. Python figures out the type automatically.
# School-themed variables
student_name = "Aarav" # string
grade = 8 # integer
average_marks = 84.33 # float
is_passed = True # boolean
print(student_name, "is in grade", grade)
Rules:
- Names can contain letters, numbers, underscores (
_), but cannot start with a number. - Case‑sensitive (
name≠Name). - Use meaningful names for readability.
2. Python Data Types
Python has several built‑in data types. The most common ones are:
| Data Type | Example | Description |
|---|---|---|
int | 8, -3, 0 | Whole numbers |
float | 3.14, 84.5 | Decimal numbers |
str | "Hello" | Text, wrapped in quotes |
bool | True, False | Logical values |
NoneType | None | Represents "nothing" or empty |
Check a type with type() (see later).
3. print() Function
The print() function displays output on the screen.
print("Hello, World!")
print("Aarav", "Grade", 8)
print("Maths", "Science", sep=" | ")
print("Welcome", end=" --> ")
print("Have a nice day!")
4. String Formatting (f‑strings)
Python's modern way is f‑strings (Python 3.6+).
name = "Aarav"
marks = 84.56
print(f"{name} scored {marks} marks.")
print(f"Rounded: {marks:.1f}")
5. input() Function
input() waits for user input and returns a string. Convert to numbers when needed.
subject = input("What is your favorite subject? ")
print("Great choice! You enjoy", subject)
maths = int(input("Enter Maths marks: "))
english = float(input("Enter English marks: "))
total = maths + english
print("Total marks:", total)
⚠️ Important: Always convert input() with int() or float() for calculations.
6. type() Function
type() returns the data type – great for debugging.
name = "Aarav"
grade = 8
average = 84.33
passed = True
print(type(name)) #
print(type(grade)) #
print(type(average))#
print(type(passed)) #
Quick Practice: Putting It All Together
student = input("Enter student name: ")
grade = int(input("Enter grade level: "))
marks = float(input("Enter average marks: "))
print("\n--- Student Summary ---")
print(f"Name : {student}")
print(f"Grade : {grade}")
print(f"Marks : {marks:.2f}")
print(f"Data types : {type(student)}, {type(grade)}, {type(marks)}")
Practice Problems
Apply what you've learned with these beginner and intermediate problems.
🔰 Beginner Level
1. Greeting Generator
Problem: Ask for first name and age, then print a personalized greeting.
first_name = input("Enter your first name: ")
age = int(input("Enter your age: "))
print(f"Hello {first_name}, you are {age} years old!")2. Simple Interest Calculator
Problem: Accept principal, rate, and time. Calculate SI = (P*R*T)/100.
principal = float(input("Enter principal amount (₹): "))
rate = float(input("Enter rate of interest (%): "))
time = float(input("Enter time (years): "))
simple_interest = (principal * rate * time) / 100
print(f"Simple Interest: ₹{simple_interest:.2f}")3. Temperature Converter (Celsius → Fahrenheit)
Problem: Convert Celsius to Fahrenheit: F = (C × 9/5) + 32.
celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = (celsius * 9/5) + 32
print(f"{celsius}°C is equal to {fahrenheit:.1f}°F")⚡ Intermediate Level
4. Swap Two Variables Without Third Variable
Problem: Swap two numbers using tuple unpacking.
a = int(input("Enter first number (a): "))
b = int(input("Enter second number (b): "))
print(f"Before swap: a = {a}, b = {b}")
a, b = b, a
print(f"After swap: a = {a}, b = {b}")Unsolved Exercises
Test yourself! No solutions here—just the problem statement.
🔰 Beginner Level
1. Rectangle Area Calculator
Problem: Ask for length and width, compute area, print rounded to 2 decimals.
2. Minutes to Hours & Minutes Converter
Problem: Convert minutes to hours and remaining minutes. Use // and %.