python string ko list me kaise change kare


जब आप Python के program बनाते है तो उस मे कभी-कभी string को लिस्ट मे बदलना होता है इस लिए आज हम आप को बताऐगे कि python string ko list me kaise change kare यह जानने के लिए पोस्ट को आखिर तक पढे और समझे।

python string ko list me kaise change kare

Python मे string को लिस्ट मे बदलने के लिए हम split() function का प्रयोग करते है। यह function हमारी string मे जितने भी word होते है उन को item मे बदल देता है और एक list मे store करता है।

s = "this is a string"
c = s.split()
print(type(c))
print(c)

Output:

<class 'list'>
['this', 'is', 'a', 'string']

ऊपर दिये गये s variable मे string store है, इस को ही हम list मे convert कर रहे है।

अब c variable मे list को store करेगे और split() function कि मदद से string list मे convert हो जाऐगी।

अब पहले print() मे हमने check किया कि c variable मे किस type का data है, जिस का output <class 'list'> आया है।

Next print() मे c मे store list को print किया गया है।

निष्कर्ष

अब आप जान गये होगे कि python string ko list me kaise change kare और इसे बदलने के लिए किस function का प्रयोग करना होता है। हमने आप को python string ko list me change karne के लिए code भी दिया है और output भी दिखाया है। आप भी इस तरह कर सकते है।

FAQ

Q1. python string ko list me change करने के लिए किस function का प्रयोग करते है?

Ans. Python string ko list me change करने के लिए split() function का प्रयोग करते है। यह split() function Python मे built-in आता है।


⬅ Back