how to get initials in python strings code example
Example 1: initials of a name in python
Raw_name = input("\nEnter Full Name : ")
name = Raw_name.strip()
bname = name.split(' ')
lenofstr = len(bname)
fname = bname[0]
leofstrstr = str(lenofstr)
vlname = int(lenofstr) - 1
lname = bname[int(vlname)]
print("\nHi,"+bname[0])
print("\nHi,",end="")
for i in bname:
if i == lname:
break
print(i[0].upper()+".",end="")
print(lname+"\n")
Example 2: Fill in the gaps in the initials function so that it returns the initials of the words contained in the phrase received, in upper case.
def get_initials(fullname):
xs = (fullname)
name_list = xs.split()
initials = ""
for name in name_list:
initials += name[0].upper()
return initials