👋 Introduction
Hi, I'm Hariom Lohar. I'm currently learning AI, with the long-term goal of moving into AGI Safety. Right now, I'm on a personal challenge, and as part of it, I'm helping others (like you!) learn programming and AI fundamentals from scratch.
This is Day 2 of our Python basics series. Yesterday we covered Variables and Data Types — today we move on to Arithmetic Operators and String Methods.
🎥 Watch the Video First
Before reading further, watch this video:
👉 String methods in Python are easy! 〰️
⚠️ Important: After watching the video, make sure to read the rest of this blog post. This video only covers String Methods — there is no video for Arithmetic Operators this time, so that part is explained fully in text below. Make sure you read through the Arithmetic Operators section carefully since you won't have a video to fall back on for it.
📖 What You'll Learn in This Post
- Each arithmetic operator in Python, explained (text-only, no video for this part)
- Operator precedence (the order Python calculates things in)
- String methods, to go along with the video
- Frequently Asked Questions (FAQs)
- A practice Python file to test yourself
➕ Arithmetic Operators
Note: There is no video for this topic — read this section carefully, it's your only source for it.
Arithmetic operators are symbols used to perform mathematical calculations on numbers (and variables holding numbers).
a = 10
b = 3
print(a + b) # Output: 13
Here, + is the arithmetic operator doing the addition.
The Arithmetic Operators in Python
+ — Addition Adds two values together.
5 + 2 # → 7
- — Subtraction Subtracts the right value from the left value.
5 - 2 # → 3
* — Multiplication Multiplies two values.
5 * 2 # → 10
/ — Division Divides the left value by the right value. Always returns a float, even if the result is a whole number.
5 / 2 # → 2.5
// — Floor Division Divides and rounds down to the nearest whole number (drops anything after the decimal point).
5 // 2 # → 2
% — Modulus Gives you the remainder left over after division.
5 % 2 # → 1
— Exponentiation Raises the left value to the power of the right value.
5 ** 2 # → 25
Operator Precedence (Order of Operations)
Just like in math class, Python doesn't calculate things strictly left to right — it follows an order of priority, often remembered using PEMDAS:
- Parentheses
() - Exponents
- Multiplication
*and Division/,//,%(same priority, left to right) - Addition
+and Subtraction-(same priority, left to right)
Example:
result = 2 + 3 * 4
print(result) # Output: 14, not 20
Python calculates 3 * 4 first (because multiplication has higher priority), then adds 2.
If you want addition to happen first, use parentheses:
result = (2 + 3) * 4
print(result) # Output: 20
❓ FAQs (Arithmetic Operators)
Q1. Why does / always give a float, even for whole-number results? Python's / is designed to always return a precise, decimal-accurate result (true division), unlike //, which intentionally rounds down.
Q2. What's the difference between / and //? / gives the exact decimal result. // gives only the whole number part, rounded down (also called floor division).
Q3. When would I actually use % (modulus)? It's commonly used to check if a number is even or odd (num % 2 == 0 means even), or to figure out remainders, like converting seconds into minutes and leftover seconds.
Q4. Does Python follow the same order of operations as regular math? Yes — Python follows PEMDAS, same as what you learned in school.
Q5. Can I combine arithmetic operators with variables? Yes. Arithmetic operators work the same way whether you use raw numbers or variables holding numbers.
🔤 String Methods
This is the part covered by the video above. Strings have built-in methods that let you change, check, or clean up text. A method is called using a dot after the variable name:
text = "hello"
print(text.upper()) # Output: HELLO
.upper() — Converts all characters to uppercase
"hello".upper() # → "HELLO"
.lower() — Converts all characters to lowercase
"HELLO".lower() # → "hello"
.strip() — Removes extra whitespace from the start and end of a string
" hello ".strip() # → "hello"
.replace(old, new) — Replaces one part of a string with another
"I like cats".replace("cats", "dogs") # → "I like dogs"
len() — Not technically a method, but a built-in function that gives you the length of a string (including spaces)
len("hello") # → 5
.startswith(text) — Checks whether a string starts with specific text, returns True or False
"hello world".startswith("hello") # → True
❓ FAQs (String Methods)
Q1. Does len() count spaces as characters? Yes. Every character, including spaces, counts toward the length.
Q2. Does .upper() or .lower() change the original variable? No. Strings in Python are immutable — these methods return a new string. You need to store the result in a variable if you want to keep it.
Q3. What does .strip() actually remove? Only whitespace (spaces, tabs, newlines) from the beginning and end — not from the middle of the string.
🐍 Practice File — Test Yourself
Now that you've watched the video and read through this post, it's time to test what you've actually understood — both Arithmetic Operators and String Methods.
Download the practice Python file below. It has guided comments and blank spaces — you need to write the code yourself.
👉 Download the Practice File Here
Once done, submit your completed file in the comment section of this blog post. I'll personally review it and give you feedback.
✅ Deadline Reminder
This task/assignment should be completed within 2 days. If you get stuck anywhere, don't hesitate to ask in the group — we're all learning together. 🙌