- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to print the initials of a name with last name in full?
Here we use different python inbuilt function. First we use split().split the words into a list. Then traverse till the second last word and upper() function is used for print first character in capital and then add the last word which is title of a name and here we use title(),title function converts the first alphabet to capital.
Example
Input Pradip Chandra Sarkar Output P.C Sarkar
Algorithm
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.
Example Code
# 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))
Output
Enter Full Name ::>pradip chandra sarkar Short Form of Name Is ::> P.C.Sarkar
- Related Articles
- Java program to print the initials of a name with last name in full
- Program to find the initials of a name in C++
- MySQL query to display columns name first name, last name as full name in a single column?
- Constructing full name from first name, last name and optional middle name in JavaScript
- Java Program to get full day name
- Program to print its script name as output in Python
- Program to print its script name as output using Python
- Write the full name of ‘SONAR’.
- Validate the first name and last name with Java Regular Expressions
- Update a table in MySQL and display only the initials name in a new column
- Python Program to Print Nth Node from the last of a Linked List
- Find all users with a unique last name in MySQL?
- How to print a variable name in C?
- MySQL query to select everything to left of last space in a column with name records
- Split First name and Last name using JavaScript?

Advertisements