String operations — concatenation, repetition
1. Concatenation with +
WHAT it does. "foot" + "ball" → "football". No space is inserted automatically — you only get exactly the characters you provide.
HOW it works (from first principles). Think of a string as a list of slots:
When you do s + t, Python builds a brand-new buffer of length len(s) + len(t), copies all of s's characters first, then all of t's characters after. The originals are untouched — strings are immutable, so an "operation" never edits in place; it returns a fresh string.
2. Repetition with *
WHY it exists. Writing "-" + "-" + "-" + ... for a 40-character line is painful. "-" * 40 says it once.
HOW it works. s * n is defined as repeated concatenation:
So it inherits all the concatenation rules.

3. Combining both
Common mistakes
Flashcards
What operator concatenates two strings in Python?
+What operator repeats a string n times?
* (with an integer)What is len(s + t) in terms of len(s) and len(t)?
len(s) + len(t)What is len(s * n)?
n * len(s) for n ≥ 0What does "hi" * 0 return?
'' (empty string)What does "hi" * -3 return?
'' (negative counts give empty string, no error)Why does "3" + 4 fail?
str with an int; convert with str(4) first.Why does "ab" * "2" fail?
int("2").Are Python strings mutable or immutable?
+/* return brand-new strings.Does "a"+"b" insert a space?
Recall Feynman: explain to a 12-year-old
Imagine letter beads on a string. Concatenation (+) is tying one bead-string onto the end of another to make a longer one — "cat" + "dog" becomes "catdog", nothing extra slipped in. Repetition (*) is a copy machine: "ha" * 3 prints "hahaha". You can't repeat something "minus two times," so Python just gives you an empty bead-string. And you can never add letter-beads to number-beads without first turning the number into letters — that's why str(4) exists.
Connections
- Strings — definition and indexing — what a string is before we operate on it.
- Immutability of strings — why
+/*return new objects. - Type conversion — str(), int(), float() — the fix for
str + interrors. - Operator overloading — same symbol, different meaning by operand type.
- f-strings and .format() — cleaner alternatives once concatenation gets long.
- len() and built-in functions — counting characters.
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, Python me string ka matlab hai characters ki ek line jo order me judi hoti hai. Do main operators hote hain string banane ke liye. Pehla hai + yaani concatenation — yeh do strings ko jod deta hai, jaise "foot" + "ball" se "football" ban jaata hai. Dhyaan rahe, beech me space khud se nahi aata; tum jo doge bas wahi milega, isliye space chahiye to "foot" + " " + "ball" likhna padega.
Doosra hai * yaani repetition — yeh ek string ko n baar copy karke jod deta hai. "ab" * 3 ka result "ababab" hota hai. Yaad rakho count hamesha integer hona chahiye. "ab" * "3" chalega nahi kyunki "3" ek string hai, number nahi. Aur agar count zero ya negative ho, to result empty string "" aata hai — error nahi aati, yeh point exam me trap karta hai.
Sabse bada concept: strings immutable hoti hain. Iska matlab + ya * kabhi original string ko change nahi karte, balki ek nayi string return karte hain. Jab tum s = s + "x" likhte ho to purani string badalti nahi, ek nayi banti hai aur naam s usko point karne lagta hai.
Ek aur common galti: "3" + 4 kaam nahi karega, kyunki ek text hai aur doosra number — Python guess nahi karta. Pehle str(4) se number ko text banao, tab + chalega. Bas yeh do operators aur yeh do-teen rules cover kar lo, to roz ki 80% string building aa jaati hai.