यहां हम विभिन्न पायथन इनबिल्ट फ़ंक्शन का उपयोग करते हैं। सबसे पहले हम स्प्लिट () का उपयोग करते हैं। शब्दों को एक सूची में विभाजित करें। फिर दूसरे अंतिम शब्द तक ट्रैवर्स और अपर () फ़ंक्शन का उपयोग कैपिटल में पहले वर्ण को प्रिंट करने के लिए किया जाता है और फिर अंतिम शब्द जो एक नाम का शीर्षक होता है और यहां हम शीर्षक () का उपयोग करते हैं, शीर्षक फ़ंक्शन पहले अक्षर को पूंजी में परिवर्तित करता है।पी>
उदाहरण
Input Pradip Chandra Sarkar Output P.C Sarkar
एल्गोरिदम
fullname(str1) /* str1 is a string */ Step 1: first we split the string into a list. Step 2: newspace is initialized by a space(“”) Step 3: then traverse the list till the second last word. Step 4: then adds the capital first character using the upper function. Step 5: then get the last item of the list.
उदाहरण कोड
# python program to print initials of a name
def fullname(str1):
# split the string into a list
lst = str1.split()
newspace = ""
# traverse in the list
for i in range(len(lst)-1):
str1 = lst[i]
# adds the capital first character
newspace += (str1[0].upper()+'.')
# l[-1] gives last item of list l.
newspace += lst[-1].title()
return newspace
# Driver code
str1=input("Enter Full Name ::>")
print("Short Form of Name Is ::>",fullname(str1))
आउटपुट
Enter Full Name ::>pradip chandra sarkar Short Form of Name Is ::> P.C.Sarkar