Python program to capitalize the first and last letter of each word of a string
Login/Signup to comment
7 comments on “Python program to capitalize the first and last letter of each word of a string”
×
30+ Companies are Hiring
Get Hiring Updates right in your inbox from PrepInsta
st=’prep insta’
ar=list(st.split(‘ ‘))
for i in range(len(ar )):
ar[i]= ar[i].replace(ar[i][0],ar[i][0].upper())
ar[i]=ar[i].replace(ar[i][-1],ar[i][-1].upper())
print(‘ ‘.join(ar))
print([i[0:1].upper() + i[1:len(i)-1] + i[-1].upper() for i in input(“-> “).split()])
my_string = input(“>”)
b = my_string[0].upper() + my_string[1:-1] + my_string[-1].upper()
print(b)
s=input()
result=”
for i in s.split():
result =result + i[0].upper()+ i[1:-1] + i[-1].upper() +” ”
print(result)
a=input().split()
for i in a:
print(i[0].upper()+i[1:len(i)-1]+i[len(i)-1].upper(),end=” “)
a=input()
print(a[0].upper()+a[1:len(a)-1]+a[len(a)-1].upper())
s=input()
n=len(s)
print(s[0].upper()+s[1:n-1]+s[-1].upper())