String Repeat

Intro

Ab aap strings ko jodna (+) bhi jaan gaye ho.
Aaj hum ek aur simple trick seekhenge: same text ko baar-baar repeat karna.
Python me string ko repeat karne ke liye * use hota hai.


Concept Explanation

WHY (Pehle “kyun”)

Kabhi-kabhi hume same word ya symbol repeat chahiye hota hai, jaise:

  • “HaHaHa”
  • “—–” (line banani ho)
  • “Go! Go! Go!”

Bar-bar manually type karna boring hai. Isliye Python me repeat ka shortcut hai.

HOW (Ab “kaise”)

1) * strings ke saath repeat karta hai

Jab aap likhte ho:
"ha" * 3
to output hota hai: hahaha (same string 3 times chipak jaati hai).

2) Space ka dhyaan

Python repeat me automatically space nahi daalta.
Agar aapko space chahiye, string ke andar hi space add kar do.
Example: "ha " * 3ha ha ha

3) Repeat count number hota hai

* ke right side me number hota hai: 2, 3, 10…
Jitna number, utni baar repeat.


Example

Hum ek word repeat karke output dekhenge.

print("ha" * 3)

print("ha " * 3)

Try It Yourself

  1. line naam ka variable banao: "-" * 20
  2. Print karo aur dekho ek long line ban gayi
  3. Phir "Go! " * 3 print karke dekho
line = "-" * 20
print(line)

print("Go! " * 3)

Summary (2 lines)

Python me strings ko repeat karne ke liye * operator use hota hai.
Space chahiye to string ke andar hi space dena padta hai.


Next

Next hum dekhenge: numbers ke saath basic maths (+ - * /).

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top