आज हम आप को python string ke sabhi function in hindi मे बताने वाले है इन का प्रयोग कर के आप अपने python program को बहुत अच्छा बना सकते है और अगर आप student है तो बहुत अच्छी तैयारी कर सकते है हम आप को सभी string function के नाम के साथ साथ इन के बारे मे information भी देगे
python string के function python program बनाने के लिए बहुत उपयोगी होते है इन के बारे मे आप को जरुर पता होना चाहिए चलिए जानते है सभी function के बारे मे
यह function string का पहला अक्षर बड़ा करता है
Example - a = "bytedg"
print(a.capitalize())
Output – Bytedg
इस function का प्रयोग कर के आप सभी String को lowercase मे बदलते है
इस function से आप string को center मे ला सकते है
text = "Python"
result = text.center(20, "*")
print(result)
output
*******Python*******
इस मे text कि लम्बाई 20 दि गयी है यह Text मे दिये गये varable को center मे करेगा और दोनो side * लगा देगा और python और * को मिला कर कुल 20 होगे
यह function हमे बताता है कि हमारी string मे कोई word या chatecter कितनी बार आया है
text = "bytedg is a best webdevelopment company"
s=text.count('a')
print(s)
इस मे हमे count function ने बताया है कि a कितनी बार आया है इस मे a दो बार आया है इस लिए इस का output भी 2 आया है
यह function हमारी string bytes मे बदलता है
text = "bytedg is a best webdevelopment company"
s=text.encode("utf-16")
print(s)
output-
b'\xff\xfeb\x00y\x00t\x00e\x00d\x00g\x00 \x00i\x00s\x00 \x00a\x00 \x00b\x00e\x00s\x00t\x00 \x00w\x00e\x00b\x00d\x00e\x00v\x00e\x00l\x00o\x00p\x00m\x00e\x00n\x00t\x00 \x00c\x00o\x00m\x00p\x00a\x00n\x00y\x00'
इस function का प्रयोग हम string का end चैक करने के लिए करते है
text = "bytedg is a best webdevelopment company"
s=text.endswith("company")
print(s)
इस program मे endswith ने check किया कि क्या String का आखरी word Company है अगर है तो यह हमे true देता है और अगर नही है तो यह हमे false देता है
इस का output - TRUE होगा
text = "Python\tProgramming\tLanguage"
print(text.expandtabs(5))
इस Function का प्रयोग table कैसे format बनाने के लिए किया जाता है इस मे हम जहाँ पर Space देते है और जो value expandtabs के अंदर देते है उतना हि cursor का space यह बिच मे create करता है
यह हमे शब्दो कि position बताता है जैसे हमे अपनी string मे किसी शब्द कि postion जानी है जैसे t कि तो हम इस के अदंर t लिखेगे और यह हमे बताऐगा कि t कि postion क्या है
text = "bytedg is a best webdevelopment company"
print(text.find("t"))
output – 2
अगर हमे अपनी string से कोई chareter या word को replace करना है तो हम replace function का प्रयोग करते है
text = "bytedg is a good webdevelopment company"
s = text.replace("good","best")
print(s)
Output - bytedg is a best webdevelopment company
इस function कि मदद से हम string के सभी words को छोटे-छोटे भोगो मे बाट सकते है जैसे list के item होते है इस तरह बाट देता है
text = "bytedg is a good webdevelopment company"
s = text.split()
print(s)
output - ['bytedg', 'is', 'a', 'good', 'webdevelopment', 'company']
इस function कि मदद से आप String मे कोई भी विशेष प्रकार का chareter , word , number आदी जोड सकते है
text = "bytedg is a good webdevelopment company"
s = "_".join(text)
print(s)
output-
b_y_t_e_d_g_ _i_s_ _a_ _g_o_o_d_ _w_e_b_d_e_v_e_l_o_p_m_e_n_t_ _c_o_m_p_a_n_y
इस program मे underscore (_) जोडा गया है
यह function string के शुरु और आखिर का Space हटा देता है
text = " Python Programming "
print(text.strip())
output- Python Programming
इस lower function कि मदद से आप कि string के सभी शब्द lowercase मे आ जात है यानी छोटी abc मे
text = "ByteDG"
print(text.lower())
Output – bytedg
इस upper function से हमारी String के सभी words Uppercase मे हो जाते है यानी बडी ABCD मे
text = "bytedg"
print(text.upper())
Output – BYTEDG
यह Function हमे true और false देता है इस मे जो string हम देते है अगर String उसी शब्द से शुरु हो रही है या फिर उसी Word से शुरु हो रही है तो यह हमे true देगा नही तो false देगा
text = "bytedg"
print(text.startswith("b"))
Output - True
अब आप python string ke sabhi function in hindi मे जान गये होगे कि कौन-कौन से function होते है string के और इन के कौन कौन से कार्य होते है
Ans हाँ python string के बहुत सारे function Built-in होते है आवश्याता होने आप अपने भी function बना सकते है
Ans Python string मे replace(), split() function बहुत ज्यादा प्रयोग होते है