Python Refresher
Basics & Syntax
Python feels close to English, but the computer still needs clear rules. This page teaches the core rules in a simple way so you can write clean code with confidence.
1. Variables: Storing Information
A variable is a named box where you keep a value.
1name = "Riya"2age = 133height = 5.14is_student = TrueWhat it is: A variable stores data.
How it is used: You save values and reuse them later.
When it is used: Almost everywhere in every program.
2. Data Types You Must Know
| Type | Example | Meaning |
|---|---|---|
int | 42 | Whole number |
float | 3.14 | Decimal number |
str | "hello" | Text |
bool | True, False | Yes/No logic |
NoneType | None | No value yet |
You can check type using:
1x = 422print(type(x))3. Input and Output
Output with print()
1score = 952print("Score:", score)3print(f"Score is {score}")Input with input()
1user_age = input("Enter age: ")2user_age = int(user_age)3print(user_age + 1)Important: input() gives text by default, so convert with int() or float() when needed.
4. Operators
Math operators
1a = 102b = 334print(a + b)5print(a - b)6print(a * b)7print(a / b)8print(a // b)9print(a % b)10print(a ** b)Comparison operators
1print(5 > 2)2print(5 == 2)3print(5 != 2)Logical operators
1is_hot = True2is_humid = False34print(is_hot and is_humid)5print(is_hot or is_humid)6print(not is_hot)5. Indentation: Python's Biggest Rule
In Python, spaces are not decoration. Spaces define code blocks.
1temperature = 3223if temperature > 30:4 print("Too hot")5 print("Turn on fan")67print("Done")If indentation is wrong, Python throws IndentationError.
Use 4 spaces
Use 4 spaces for each level. Do not randomly mix tabs and spaces.
6. Conditions (if, elif, else)
Conditions help code make decisions.
1marks = 7823if marks >= 90:4 grade = "A"5elif marks >= 75:6 grade = "B"7else:8 grade = "C"910print(grade)What it is: Decision logic.
How it is used: Run one path if condition is true, another path otherwise.
When it is used: Validation, filtering, alerts, business rules.
7. Loops
for loop (known range or collection)
1for i in range(5):2 print(i)while loop (repeat until condition changes)
1count = 02while count < 3:3 print(count)4 count += 1What it is: Repetition.
How it is used: Run same action for many values.
When it is used: Reading rows, processing sensor samples, retrying tasks.
8. Strings (Text Handling)
1message = "analog data"23print(message.upper())4print(message.lower())5print(message.replace("analog", "edge"))6print(len(message))Common beginner need: formatting text with variables:
1name = "Aarav"2score = 913print(f"{name} scored {score}")9. Basic Error Handling (try/except)
1try:2 x = int(input("Enter a number: "))3 print(100 / x)4except ValueError:5 print("Please enter a valid integer")6except ZeroDivisionError:7 print("Cannot divide by zero")What it is: A safe way to handle runtime errors.
How it is used: Wrap risky code in try, recover in except.
When it is used: User input, file access, network calls, parsing.
10. Good Habits from Day 1
- Use meaningful variable names:
temperature_c, nott. - Keep functions small and focused.
- Add comments only where logic is not obvious.
- Print intermediate values while debugging.
- Run code in small steps, not as one giant file.
Tiny Practice Problems
- Ask user for two numbers and print sum, product, and average.
- Ask user marks and print grade using
if/elif/else. - Print all even numbers from 1 to 50.
- Count how many vowels are present in a word.
If you can solve these comfortably, your basics are strong.

