Home >> Python Tutorial >> Python String
Edit Template
Edit Template

Python String

What is Python String in Hindi

Python String : Single and double quote के अंदर हम कुछ लिखते हैं तो यह string कहलाता है.

Triple quote के अंदर हम कुछ लिखते हैं तो भी यह string कहलाता है इसका use हम multi line string के लिए करते हैं.

🐍
string.py
Copy to clipboard
print("this is single line string")
print("""this is
multi-line
string""")

String Indexing in Hindi

अगर हम string में से किसी specific data को print करना चाहते हैं तो indexing का use करते हैं.

 python string में characters का indexing 0 से start होता है, और negative indexing end से start होता है  -1 last character को represent करता है.

🐍
string indexing.py
Copy to clipboard
text = "hello, world!"
print(text[0])
print(text[-1])
#output
#   h
#   !

String Slicing in Hindi

slicing का use string के Sab string पाने के लिए होता है,

start: Ye wo index hai jahan se slicing start hoti hai.

stop: Ye wo index hai jahan tak slicing hoti hai.

step: Ye optional parameter hai jo batata hai ki kitne steps ka difference rakhna hai.

Agar aap start, stop, ya step ko nahi dete, to default values use hoti hain:

Default value for start is 0.

Default value for stop is length of the string.

Default value for step is 1

🐍
string slicing.py
Copy to clipboard
text = "hello, world!"
print(text[0:5])
print(text[7:])
print(text[:5])
print(text[-6:-1])
print(text[0:5:2])
#output
# hello
# world!
# hello
# world
# hlo

String Concatenation in Hindi

string concatenation का मतलब होता है एक या एक से अधिक strings को add करके single string मे convert करना। 

string को concatenate करने के लिए + operator या join methode का use किया जाता है।

🐍
string concatenation.py
Copy to clipboard
a = "python"
b = "programing"
c = "hub"

# using + operator
print(a +" "+ b +" "+ c)

# using join methode
print(" ".join([a,b,c]))

# output
# python programing hub
# python programing hub

NOTE: string concatenation मे हमने double quote ( ” ” ) का use इसलिए किया है ताकि हम strings के बीच मे space दे सके अगर double quote नहीं लगाएंगे तो सारे strings एक मे mix होकर single word बन जाएंगे। 

अगर आप double quote के अंदर कुछ लिखेंगे तो वो भी string मे join हो जाएगा।

String Formatting in Hindi

अगर हम चाहते है कि string मे variables या expressions के value को direct insert कर सके तो हमे string formatting का उसे करना होगा। python मे string formatting बनाने के लिए % operator, str.format() method और f-strings का use करते है। 

% Operator

🐍
formatting 1.py
Copy to clipboard
name = "Lisa"
age = 25
print("Hello my name is %s and I am %d year old." %(name, age))

str.format Method

🐍
formatting 2.py
Copy to clipboard
name = "Lisa"
age = 25
print("My name is {} and I am {} years old.".format(name, age))
# Output: My name is Lisa and I am 25 years old.

f-strings

🐍
formatting 3.py
Copy to clipboard
name = "Lisa"
age = 25
print(f"My name is {name} and I am {age} years old.")
# Output: My name is Charlie and I am 35 years old.

# Aap expressions bhi use kar sakte hain
print(f"Next year, I will be {age + 1} years old.")
# Output: Next year, I will be 26 years old.

String Methods in Hindi

python मे string के लिए कई सारे build-in methods होते है जिन्हे use करने पर string अलग अलग तरीके से perform करता है।

Syntex:

method को किसी भी variable के साथ use करने के लिए dot ( . ) का use करते है।

Example:

str.upper() : इस method का use करके हम string के सभी lower case letters को upper case मे कर सकते है। 

🐍
string method.py
Copy to clipboard
text = "hello"
result = text.upper()
print(result)  
# Output: HELLO

upper():  String को uppercase मे convert करता है।

lower():  String को lowercase मे convert करता है।

capitalize():  पहला letter uppercase करता है, बाकी lowercase

title():  हर word का पहला letter uppercase करता है।

strip():  Start और end के whitespace (या characters) remove करता है।

lstrip():  Left से whitespace (या characters) remove करता है।

rstrip():  Right से whitespace (या characters) remove करता है। 

replace(old, new):  String मे किसी substring को replace करता है।

split(separator):  String को list मे break करता है।

str.join(iterable):  List (या iterable) को string मे add करता है।

str.find(sub):  Substring का index return करता है (अगर नहीं मिल तो -1 return करेगा)

str.index(sub):  Substring का index देता है।

str.count(sub):  Substring कितनी बार आया है, वो count करता है।

str.isalpha():  Check करता है की सब characters alphabets है या नहीं अगर है तो true return करेगा। 

str.isdigit():  Check करता है की सभी  characters digits है या नहीं अगर है तो true return करेगा। 

str.isalnum():  Alphabets + Digits है तो True return करता है । 

str.isspace():  अगर string मे सिर्फ whitespace है तो  True return करेगा।

str.islower():  Check करता है की string lowercase मे है या नहीं। अगर है तो true return करेगा।

str.isupper():  Check करता है की string uppercase मे है या नहीं, अगर है तो true return करेगा।

उम्मीद करते है कि आपको python string अच्छे समझ मे आ गया होगा । अपने learning को continue रखने के लिए next button पर click करे,

Add a comment...

  • All Posts
  • Artificial Intelligence
  • Computer Fundamentals
  • Computer Networks
  • Data Analytics
  • Data Science
  • DBMS
  • Deep Learning
  • Digital Fundamentals
  • DSA with Python
  • Excel
  • Exercise
  • Git & Github
  • Machine Learning
  • Matplotlib
  • Natural Language Processing
  • NumPy
  • Operating System
  • Pandas-s
  • Power BI
  • Python Tutorial
  • Scikit-learn
  • Seaborn
  • SQL & MySQL
Python Function

Table of Contents All Chapters 1. Python Function 2. Define Function 3. Function Arguments 4. Function Parameters 5. Local and...

Python Dictionary

Table of Contents All Chapters 1. Python Dictionary 2. Access Dictionary items 3. Change Dictionary items 4. Add items in...

Python Set

Table of Contents All Chapters 1. Python Set 2. Iterate Set items 3. Set Methods      3.1. Add items...

Python Tuple

Table of Contents All Chapters 1. Python Tuple 2. Access Tuple Items 3. Update Tuple 4. Iterate Tuple Items 5....

Python List

Table of Contents All Chapters 1. Python List 2. Nested List 3. Range List 4. List Indexing 5. list Methods...

Python String

Table of Contents All Chapters 1. Python String 2. String Indexing 3. String Slicing 4. String Concatenation 5. String Formatting...

Python Loops

Table of Contents All Chapters 1. Python Loops 2. While Loop      2.1. Nested While Loop 3. For Loop...

Edit Template
Scroll to Top