Python me Strings kya hoti hain?


String ek text data type hai jisme hum letters, words, sentences, numbers ya koi bhi characters store kar sakte hain. Python me string ko single quotes (' '), double quotes (" ") ya triple quotes (''' ''' ya """ """) me likha jaata hai.

Is page me yeh sab sikhenge :-

Note :- Python me String immutable hoti hai — matlab ek baar banne ke baad string ke andar ka koi character directly change nahi ho sakta. Har string method naya string return karta hai, original change nahi hota.



1. String Banana — Different Ways

Python me string banane ke 4 tarike hain. Teeno quotes me se koi bhi use kar sakte hain, lekin triple quotes multi-line strings ke liye use hote hain.

Example 1: Single, double aur triple quotes

Python
In [1]:
1
Output

Example 2: String me quotes ke andar quotes likhna

Python
In [1]:
1
Output


2. Indexing aur Slicing

String ke har character ka ek index (number) hota hai. Python me indexing 0 se shuru hoti hai. Negative index end se shuru hota hai.

StringPython
Positive Index012345
Negative Index-6-5-4-3-2-1

Example 1: Indexing — kisi bhi ek character access karna

Python
In [1]:
1
Output

Example 2: Slicing — string ka ek hissa nikalna [start:stop:step]

Python
In [1]:
1
Output

Example 3: Slicing se Palindrome check karna

Python
In [1]:
1
Output


3. String Concatenation aur Repetition

Concatenation ka matlab hai do ya zyada strings ko jodna+ operator se. Repetition ka matlab hai string ko baar baar repeat karna* operator se.

Example 1: Concatenation — strings jodhna

Python
In [1]:
1
Output

Example 2: Repetition — string ko repeat karna

Python
In [1]:
1
Output


4. f-String aur format()

String ke andar variables ki values seedha daal ne ke liye f-string ya format() use karte hain. f-string modern aur easy tarika hai.

Example 1: f-String — curly braces me variable daalo

Python
In [1]:
1
Output

Example 2: format() method — purana tarika

Python
In [1]:
1
Output


5. Escape Characters

Kuch special characters string me directly nahi likh sakte — jaise newline, tab ya quotes. Inke liye backslash (\) se shuru hone wale escape characters use hote hain.

Escape CharMatlab
\nNew line (naya line)
\tTab (space)
\\Backslash (\)
\'Single quote
\"Double quote

Example 1: \n aur \t ka use

Python
In [1]:
1
Output

Example 2: Quotes aur backslash escape

Python
In [1]:
1
Output


6. String Methods

Python me strings ke saath bahut saare built-in methods aate hain jo string pe kaam karte hain. Ye methods original string change nahi kartenaya string return karte hain.

Example 1: Case methods — upper, lower, title, capitalize, swapcase

Python
In [1]:
1
Output

Example 2: strip() — extra spaces hatana

Python
In [1]:
1
Output

Example 3: find(), count() aur replace()

Python
In [1]:
1
Output

Example 4: split() aur join()

Python
In [1]:
1
Output

Example 5: Check karne wale methods — startswith, endswith, isdigit, isalpha

Python
In [1]:
1
Output

Example 6: Alignment methods — center, ljust, rjust, zfill

Python
In [1]:
1
Output



Quick Summary — Important String Methods ek nazar me

MethodKaamExample
upper()Sab capitals"hi".upper() → "HI"
lower()Sab small"HI".lower() → "hi"
title()Har word capital"hi world".title() → "Hi World"
strip()Spaces hatao" hi ".strip() → "hi"
replace()Text badlo"hi".replace("h","b") → "bi"
split()List me todo"a b".split() → ["a","b"]
join()List se jodo"-".join(["a","b"]) → "a-b"
find()Index dhundo"hi".find("i") → 1
count()Kitni baar aaya"aaa".count("a") → 3
startswith()Kya isse shuru hota hai"hi".startswith("h") → True
endswith()Kya isme khatam hota hai"hi".endswith("i") → True
isdigit()Sirf numbers hain?"123".isdigit() → True
isalpha()Sirf letters hain?"abc".isalpha() → True