Python में String सबसे अधिक उपयोग होने वाले Data Types में से एक है। String को खोजने (Search), बदलने (Replace), विभाजित (Split), जोड़ने (Join), साफ़ करने (Trim), जाँचने (Check) और Format करने के लिए Python अनेक Built-in String Methods प्रदान करता है।
ये Methods Programming, Web Development, Data Analysis, Automation, Competitive Programming तथा Interview Coding में सबसे अधिक उपयोग किए जाते हैं।
इस अध्याय में Python के 40+ महत्वपूर्ण String Methods को Syntax, Examples और Output सहित विस्तार से समझेंगे।
String Methods वे Built-in Functions हैं जो String Object पर विभिन्न प्रकार के Operations करने के लिए उपयोग किए जाते हैं।
string.method_name()
उदाहरण
text = "python"
print(text.upper())
Output
PYTHON
Python के String Methods को समझने में आसानी के लिए इन्हें विभिन्न श्रेणियों में बाँटा जा सकता है—
- upper()
- lower()
- capitalize()
- title()
- swapcase()
- casefold()
- find()
- rfind()
- index()
- rindex()
- count()
- replace()
- removeprefix()
- removesuffix()
- split()
- rsplit()
- splitlines()
- join()
- partition()
- rpartition()
- strip()
- lstrip()
- rstrip()
- center()
- ljust()
- rjust()
- zfill()
- isalpha()
- isdigit()
- isnumeric()
- isdecimal()
- isalnum()
- islower()
- isupper()
- istitle()
- isspace()
- isidentifier()
- isascii()
- isprintable()
- format()
- format_map()
- expandtabs()
- encode()
- maketrans()
- translate()
- startswith()
- endswith()
|
क्रम |
Method |
उपयोग |
|
1 |
upper() |
बड़े अक्षरों में बदलना |
|
2 |
lower() |
छोटे अक्षरों में बदलना |
|
3 |
capitalize() |
पहला अक्षर बड़ा करना |
|
4 |
title() |
प्रत्येक शब्द का पहला अक्षर बड़ा |
|
5 |
swapcase() |
Upper ↔ Lower बदलना |
|
6 |
casefold() |
Case-insensitive तुलना |
|
7 |
find() |
पहली Position खोजता है |
|
8 |
rfind() |
पीछे से खोजता है |
|
9 |
index() |
Position देता है |
|
10 |
rindex() |
पीछे से Position देता है |
|
11 |
count() |
कितनी बार आया |
|
12 |
replace() |
Text बदलना |
|
13 |
split() |
String विभाजित करना |
|
14 |
rsplit() |
पीछे से Split |
|
15 |
splitlines() |
Lines में बाँटना |
|
16 |
join() |
जोड़ना |
|
17 |
partition() |
तीन भागों में बाँटना |
|
18 |
rpartition() |
पीछे से Partition |
|
19 |
strip() |
दोनों ओर Space हटाना |
|
20 |
lstrip() |
बाईं ओर Space हटाना |
|
21 |
rstrip() |
दाईं ओर Space हटाना |
|
22 |
center() |
Center Alignment |
|
23 |
ljust() |
Left Alignment |
|
24 |
rjust() |
Right Alignment |
|
25 |
zfill() |
Zero Fill |
|
26 |
startswith() |
शुरुआत जाँचना |
|
27 |
endswith() |
अंत जाँचना |
|
28 |
isalpha() |
केवल Letters |
|
29 |
isdigit() |
केवल Digits |
|
30 |
isnumeric() |
Numeric Value |
|
31 |
isdecimal() |
Decimal Digits |
|
32 |
isalnum() |
Letters + Numbers |
|
33 |
isspace() |
केवल Space |
|
34 |
islower() |
Lowercase Check |
|
35 |
isupper() |
Uppercase Check |
|
36 |
istitle() |
Title Case Check |
|
37 |
isidentifier() |
Valid Identifier |
|
38 |
isascii() |
ASCII Check |
|
39 |
isprintable() |
Printable Characters |
|
40 |
encode() |
Encoding |
|
41 |
expandtabs() |
Tab Expand |
|
42 |
format() |
Formatting |
|
43 |
format_map() |
Dictionary Formatting |
|
44 |
maketrans() |
Translation Table |
|
45 |
translate() |
Characters बदलना |
|
46 |
removeprefix() |
Prefix हटाना |
|
47 |
removesuffix() |
Suffix हटाना |
अब इस Master Guide के बाद हर Method का Dedicated Article बनाया जाएगा।
उदाहरण—
- upper() Method in Python
- lower() Method in Python
- capitalize() Method in Python
- title() Method in Python
- swapcase() Method in Python
- casefold() Method in Python
- find() Method in Python
- replace() Method in Python
- split() Method in Python
- join() Method in Python