>>> " ".join(['hello', "good", "morning"])
'hello good morning'
या आप string.join()
समारोह, जो डिफ़ॉल्ट विभाजक के रूप में एक भी स्थान का उपयोग करता उपयोग कर सकते हैं।
>>> help(string.join)
Help on function join in module string:
join(words, sep=' ')
join(list [,sep]) -> string
Return a string composed of the words in list, with
intervening occurrences of sep. The default separator is a
single space.
उदाहरण:
" ".join(['hello', 'good', 'morning'])
आम तौर पर, जब आप कुछ स्ट्रिंग पर join()
बुला रहे हैं आप " "
का उपयोग सूची तत्वों के बीच विभाजक निर्दिष्ट करने के लिए:
>>> import string
>>> string.join(['hello', "good", "morning"])
'hello good morning'
स्रोत
2011-12-17 16:45:21
क्यों नहीं दिखाया गया कि आपने "string.join() कमांड का उपयोग कैसे किया"? –