What Is Python and Why Should You Learn It?
Think about this: you want to tell your friend how to make chai. You'd say it in Malayalam or English — a language you both understand. A computer only understands its own language, called machine code — which is basically millions of zeros and ones. Writing in zeros and ones is painful. So we use programming languages like Python as a translator.
You write instructions in Python. Python translates them into machine code. The computer runs them. Simple.
Python is a programming language — a set of rules for writing instructions that a computer can execute. It was designed to be as close to plain English as possible, which makes it the best first language to learn.
Why Python specifically?
- Used in AI and Machine Learning — the same tools behind ChatGPT, image recognition, recommendation systems
- Used in automation — write a script to rename 10,000 files in seconds instead of doing it manually
- Used in web development, data science, finance, biomedical research
- Readable syntax — Python code almost reads like English sentences
- Huge community — if you get stuck, someone has already asked your question and answered it on Stack Overflow
Your very first Python instruction
The most important thing in any new language is saying "hello." In Python, print() is the function that displays something on the screen. Think of it as Python's way of speaking out loud.
print("Hello, World!")
print("My name is Python")
Run those two lines and you will see both messages appear. Every word inside the quotes is displayed exactly as written. The print() function will become your best debugging friend — whenever something goes wrong, print the value and see what Python is actually seeing.
Open Python (IDLE, VS Code, or even an online editor like replit.com) and type: print("My college is the best!"). Change the text and run it again. You just wrote and executed a Python program.
Variables — The Labelled Boxes
Imagine you have a tiffin box. The box itself is the variable. The food inside is the value. You write your name on the box so you know which one is yours. Later you can swap the food inside — the box stays the same, only the contents change.
In Python, a variable is a labelled storage location in the computer's memory. You create one by writing a name, the = sign, and the value you want to store.
name = "Arjun" age = 20 marks = 95.5 is_passed = True print(name) # Output: Arjun print(age) # Output: 20 print(marks) # Output: 95.5
Now if Arjun's marks change after a revaluation, you just update the variable. Everything that uses marks automatically gets the new value — you don't have to hunt through your entire program and change it everywhere.
marks = 95.5 print(marks) # Output: 95.5 marks = 97.0 # Revaluation result print(marks) # Output: 97.0 — same box, new food inside
Rules for naming variables
- No spaces — use underscore instead:
student_namenotstudent name - Cannot start with a number —
2marksis invalid,marks2is fine - Case-sensitive —
Nameandnameare two different variables - Only letters, numbers, and underscores — no special characters like @, #, -
- Keep names meaningful —
student_ageis better thanx
Python uses = to assign a value, not to compare. If you write marks = 95 you are putting 95 into the box. If you want to ask "are the marks equal to 95?" you use == (double equals). Mixing these up is one of the most common beginner errors.
Data Types — Not All Information Is the Same
A good tiffin box has separate compartments — one for rice, one for curry, one for pickle. You would not mix them all into one compartment (well, most people wouldn't). Similarly, Python understands that different kinds of information need to be handled differently. These different kinds are called data types.
int — Whole Numbers
Short for "integer." These are counting numbers — no decimal point. Roll numbers, years, quantities, sensor readings that come as whole numbers.
float — Decimal Numbers
Short for "floating point number." These have a decimal point. Percentages, voltage readings, GPS coordinates, temperatures.
str — Text (Strings)
Short for "string." Any text goes in quotes — single or double, both work. Even if a number is inside quotes, Python treats it as text, not a number. So "42" is not the same as 42.
bool — True or False
Short for "boolean." Only two possible values: True or False (capital T and F). Like a yes/no question — "Did the student pass?" True or False. "Is the sensor triggered?" True or False.
roll_number = 42 # int percentage = 87.5 # float student_name = "Meera" # str has_submitted = True # bool # Check what type any variable is: print(type(roll_number)) # <class 'int'> print(type(percentage)) # <class 'float'> print(type(student_name)) # <class 'str'> print(type(has_submitted)) # <class 'bool'>
The type() function is your X-ray vision. Whenever you are not sure what type a variable is, just print its type. This saves hours of debugging because operations that work on numbers will crash on strings and vice versa.
If you read input from a user with input(), Python always gives you a string, even if the user typed a number. You have to convert it: age = int(input("Enter age: ")). Forgetting this causes confusing bugs where "5" + "3" gives you "53" instead of 8.
Operators — Making Python Do the Work
An operator is a symbol that tells Python to perform an operation. Just like a calculator has +, -, ×, ÷ buttons, Python has operators for math, comparisons, and combining conditions.
Arithmetic Operators
a = 17 b = 5 print(a + b) # Addition → 22 print(a - b) # Subtraction → 12 print(a * b) # Multiplication → 85 print(a / b) # Division → 3.4 (always gives float) print(a // b) # Floor division → 3 (removes decimal part) print(a % b) # Modulus/remainder → 2 (17 = 5×3 + 2) print(a ** b) # Power/exponent → 1419857 (17 to the power 5)
The % operator gives the remainder after division. It is incredibly useful: number % 2 == 0 tells you if a number is even. In embedded systems, counter % 10 lets you do something every 10th iteration without an extra counter variable.
A Practical Example — Calculating Percentage
marks_obtained = 427 total_marks = 500 percentage = (marks_obtained / total_marks) * 100 print(percentage) # Output: 85.4
Comparison Operators — Asking Yes/No Questions
Comparison operators always return True or False. They are the foundation of all decision-making in code.
score = 78 print(score == 78) # Equal to? → True print(score != 100) # Not equal to? → True print(score > 60) # Greater than? → True print(score < 40) # Less than? → False print(score >= 78) # Greater or equal? → True print(score <= 77) # Less or equal? → False
Logical Operators — Combining Conditions
Like combining sentences: "If it is raining AND you don't have an umbrella, take the bus." In Python, and, or, and not combine True/False values.
attendance = 80 marks = 72 # and: BOTH conditions must be True is_eligible = attendance >= 75 and marks >= 40 print(is_eligible) # False (attendance is 80 ✓, marks is 72 ✓... wait) # Let's recalculate — both are above threshold: attendance = 80 # 80 >= 75 → True marks = 72 # 72 >= 40 → True is_eligible = attendance >= 75 and marks >= 40 print(is_eligible) # True # or: AT LEAST ONE must be True has_grace = attendance < 75 or marks < 40 print(has_grace) # False (neither condition is True) # not: flips True to False and vice versa print(not True) # False print(not False) # True
Your First Real Program
Theory is good. Programs are better. Let's build something that actually does something useful: a program that takes a student's marks, calculates their percentage, and tells them whether they passed or failed.
This uses everything from this page — variables, data types, arithmetic operators, and comparison operators — all in one place.
# Student Result Calculator
# Paste this into Python and run it
student_name = "Rahul" # str
marks_obtained = 342 # int
total_marks = 500 # int
passing_marks = 200 # int (40% of 500)
# Calculate percentage using arithmetic operators
percentage = (marks_obtained / total_marks) * 100
# Check result using comparison operator
is_passed = marks_obtained >= passing_marks # bool: True or False
# Display results
print("--- Result Card ---")
print("Student:", student_name)
print("Marks:", marks_obtained, "/", total_marks)
print("Percentage:", percentage, "%")
print("Result:", is_passed) # Will print True or False
# Make it more readable:
if is_passed:
print("Status: PASS - Congratulations!")
else:
print("Status: FAIL - Work harder next time.")
Do not worry about the if/else part yet — we cover that in detail in Python 102. For now, just notice how the variables, operators, and types all work together to make something useful.
Change the values of marks_obtained and total_marks and run the program again. Then try this extension: add a variable num_subjects = 6 and calculate CGPA as cgpa = (percentage / 9.5) (a common conversion formula used by many Indian universities). Print the CGPA alongside the percentage.
