Python Basics: Complete Revision Notes 9th-AI

Published on December 12, 2025 by @mritxperts

Introduction

1. Python File Extension

Python programs are saved with the .py extension. When you create a Python file, always name it something like program.py or calculator.py.

Remember:

  • Correct: myprogram.py
  • Incorrect: myprogram.python, myprogram.pt

2. Operators and Order of Operations

Arithmetic Operators

Python follows the PEMDAS/BODMAS rule for order of operations:

  • Parentheses/Brackets – ()
  • Exponentiation – **
  • Multiplication & Division – *, /, //, %
  • Addition & Subtraction – +, –

Example:

print(10 + 5 * 2)  # Output: 20
# Multiplication happens first: 5 * 2 = 10
# Then addition: 10 + 10 = 20

Important Operators

OperatorPurposeExample
+Addition5 + 3 = 8
-Subtraction5 - 3 = 2
*Multiplication5 * 3 = 15
/Division (with decimal)5 / 2 = 2.5
//Floor Division (integer)5 // 2 = 2
%Modulus (remainder)5 % 2 = 1
**Exponentiation (power)5 ** 2 = 25

Key Difference: / vs //

  • / (Division): Gives the complete answer with decimals print(7 / 2) # Output: 3.5
  • // (Floor Division): Gives only the whole number part print(7 // 2) # Output: 3

3. Data Types in Python

Boolean Data Type (bool)

The bool data type stores only two values:

  • True
  • False

Example:

is_student = True
is_adult = False
print(5 > 3)  # Output: True

Common Data Types Summary

Data TypeDescriptionExample
intWhole numbers10, -5, 0
floatDecimal numbers3.14, -0.5
strText/String"Hello", 'Python'
boolTrue/FalseTrue, False

4. Essential Python Functions

The print() Function

Used to display output on the screen.

print("Hello World")
print(10 + 5)
print("Sum:", 15)

Variables

A variable is a named memory location that stores data.

name = "Rahul"
age = 15
marks = 95.5
is_passed = True

Rules for Variable Names:

  • Can contain letters, numbers, and underscores
  • Must start with a letter or underscore
  • Case-sensitive (Name and name are different)
  • No spaces allowed

Type Conversion Functions

int() – Converts to integer

num = int("25")  # Converts string "25" to integer 25
x = int(3.9)     # Converts float 3.9 to integer 3

Other conversion functions:

  • float() – Converts to decimal number
  • str() – Converts to string

5. Python Syntax Rules

Case Sensitivity

Python is case-sensitive, meaning uppercase and lowercase letters are treated differently.

Name = "John"
name = "Jane"
print(Name)  # Output: John
print(name)  # Output: Jane

Comments

The # symbol is used for single-line comments.

# This is a comment
print("Hello")  # This is also a comment

Indentation

Indentation (spaces at the beginning of a line) is used to define a block of code in Python.

if age >= 18:
    print("You can vote")  # This line is indented
    print("Welcome!")      # This line is also indented

6. Taking User Input

Use the input() function to get input from users:

name = input("Enter your name: ")
age = int(input("Enter your age: "))  # Convert to integer

7. Sample Programs You Must Practice

Program 1: Sum of Two Numbers

# Taking input from user
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

# Calculating sum
sum = num1 + num2

# Displaying output
print("Sum =", sum)

Program 2: Simple Interest Calculator

# Input
principal = float(input("Enter principal amount: "))
rate = float(input("Enter rate of interest: "))
time = float(input("Enter time period (years): "))

# Calculate Simple Interest
simple_interest = (principal * rate * time) / 100

# Output
print("Simple Interest =", simple_interest)

Formula: SI = (P × R × T) / 100

Program 3: Check Even or Odd Number

# Input
number = int(input("Enter a number: "))

# Check if even or odd
if number % 2 == 0:
    print(number, "is Even")
else:
    print(number, "is Odd")

Logic: If a number is divisible by 2 (remainder is 0), it’s even. Otherwise, it’s odd.

Program 4: Voting Eligibility Checker

# Input
age = int(input("Enter your age: "))

# Check eligibility using simple if statement
if age >= 18:
    print("You are eligible to vote")
if age < 18:
    print("You are not eligible to vote")

Note: Voting age in India is 18 years.


Quick Revision Checklist

make sure you can:

✅ Write the correct Python file extension (.py)
✅ Calculate expressions using BODMAS rule
✅ Identify data types (int, float, str, bool)
✅ Know all arithmetic operators, especially ** and //
✅ Use print() to display output
✅ Create and use variables
✅ Convert strings to integers using int()
✅ Write comments using #
✅ Use proper indentation in if statements
✅ Take input from users using input()
✅ Write programs for: sum, simple interest, even/odd, voting eligibility


Common Mistakes to Avoid

  1. Forgetting to convert input(): input() always returns a string, so convert it to int or float when needed.
  2. Incorrect operator: Use ** for power, not ^
  3. Wrong division operator: Remember the difference between / and //
  4. Indentation errors: Always indent code inside if statements properly
  5. Case sensitivity: print and Print are different in Python

Practice Tips

  1. Write code by hand – Practice writing programs on paper
  2. Run programs – Type and execute each program on your computer
  3. Modify examples – Change values and see what happens
  4. Solve previous papers – Practice similar questions
  5. Understand logic – Don’t just memorize, understand why the code works