How To Print Initials Of A Name In Python

Printing initials of a name is a basic operation when it comes to working with names in Python. This tutorial will guide you on how to do that easily.


1. Get the name as input from the user:
To get the input from the user, you can use the input() function in Python. The input function will get the name from the user as a string.

Example code:

2. Split the name into words:

The next thing you need to do is to split the name into words using the split() function. This will allow you to work with each word separately.

Example code:

3. Get the first letter of each word:

Once you have the words, you can get the first letter of each word using indexing. This can be done by specifying the index of the first letter in the word.

Example code:

4. Print the initials:

Finally, you can print the initials using the print() function.

Example code:

Full Code:


Enter your name: Tomasz Decker
Initials: TD


In this tutorial, you learned how to print the initials of a name in Python. This can be done by getting the name from the user, splitting it into words, getting the first letter of each word, and then printing the initials.

This operation can come in handy when you need to print the initials of a large number of names at once.