How do you print the first letter of each word in a string in python?


Assuming that the list is collection of strings, the first character of each string is obtained as follows −

>>> L1=['aaa','bbb','ccc']
>>> for string in L1:
print (string[0])

a
b
c

If list is a collection of list objects. First element of each list is obtained as follows −

>>> L1=[[1,2,3],[4,5,6],[7,8,9]]
>>> for list in L1:
print (list[0])

1
4
7

How do you print the first letter of each word in a string in python?

Updated on 18-Jun-2020 13:35:47

  • Related Questions & Answers
  • How to print the first character of each word in a String in Java?
  • Java Program to Capitalize the first character of each word in a String
  • Print number of words, vowels and frequency of each character
  • Java Program to Print first letter of each word using regex
  • How to extract the first row of each matrix stored in a list in R?
  • Print first letter of each word in a string in C#
  • Frequency of each character in String in Python
  • How to set the first day of each week to weekday using Python?
  • How to remove the first character of string in PHP?
  • Get first element of each sublist in Python
  • Print first letter of each word in a string using C# regex
  • How to print out the contents of a vector in C++?
  • How to find the first character of a string in C#?
  • Python | Sort the values of first list using second list
  • How do make a flat list out of list of lists in Python?

Lets say there is a string such as "this is a sample python program". 

How to write a program such that it would print the first character of each word in the string. such as T,I,A,S,P,P

i.e. This Is A Sample Python Program ?

How do you print the first letter of each word in a string in python?
Jun 1, 2018 in Python by
• 170 points
9,690 views

2 answers to this question.

You can use split() using space as delimiter to fetch each word and then use counter-chindex to find if it is first character of each word. If yes, then apply upper()

Below is the sample code:

s1="this is a sample python program"
s1.split(" ")
chindex=1
for letter in s1.split(" "):
     if chindex==1:
         print(letter[0].upper()+""+letter[1:len(letter)], end=" ")
     else:
         print(letter)

How do you print the first letter of each word in a string in python?
answered Jun 1, 2018 by george
• 200 points

class Solution:

    def firstAlphabet(self, s):

            self.s=s

             k=''

             k=k+s[0]

             for i in range(len(s)):

                    if s[i].isalpha():

                           pass

                    else:

                            k=k+s[i+1]

               return k

How do you print the first letter of each word in a string in python?
answered Oct 28, 2020 by Anurag

  • All categories
  • How do you print the first letter of each word in a string in python?
    Apache Kafka (84)
  • How do you print the first letter of each word in a string in python?
    Apache Spark (596)
  • How do you print the first letter of each word in a string in python?
    Azure (131)
  • How do you print the first letter of each word in a string in python?
    Big Data Hadoop (1,907)
  • How do you print the first letter of each word in a string in python?
    Blockchain (1,673)
  • How do you print the first letter of each word in a string in python?
    C# (124)
  • How do you print the first letter of each word in a string in python?
    C++ (268)
  • How do you print the first letter of each word in a string in python?
    Career Counselling (1,060)
  • How do you print the first letter of each word in a string in python?
    Cloud Computing (3,356)
  • How do you print the first letter of each word in a string in python?
    Cyber Security & Ethical Hacking (145)
  • How do you print the first letter of each word in a string in python?
    Data Analytics (1,266)
  • How do you print the first letter of each word in a string in python?
    Database (853)
  • How do you print the first letter of each word in a string in python?
    Data Science (75)
  • How do you print the first letter of each word in a string in python?
    DevOps & Agile (3,500)
  • How do you print the first letter of each word in a string in python?
    Digital Marketing (111)
  • How do you print the first letter of each word in a string in python?
    Events & Trending Topics (28)
  • How do you print the first letter of each word in a string in python?
    IoT (Internet of Things) (387)
  • How do you print the first letter of each word in a string in python?
    Java (1,178)
  • How do you print the first letter of each word in a string in python?
    Kotlin (3)
  • How do you print the first letter of each word in a string in python?
    Linux Administration (384)
  • How do you print the first letter of each word in a string in python?
    Machine Learning (337)
  • How do you print the first letter of each word in a string in python?
    MicroStrategy (6)
  • How do you print the first letter of each word in a string in python?
    PMP (423)
  • How do you print the first letter of each word in a string in python?
    Power BI (516)
  • How do you print the first letter of each word in a string in python?
    Python (3,154)
  • How do you print the first letter of each word in a string in python?
    RPA (650)
  • How do you print the first letter of each word in a string in python?
    SalesForce (92)
  • How do you print the first letter of each word in a string in python?
    Selenium (1,569)
  • How do you print the first letter of each word in a string in python?
    Software Testing (56)
  • How do you print the first letter of each word in a string in python?
    Tableau (608)
  • How do you print the first letter of each word in a string in python?
    Talend (73)
  • How do you print the first letter of each word in a string in python?
    TypeSript (124)
  • How do you print the first letter of each word in a string in python?
    Web Development (2,999)
  • How do you print the first letter of each word in a string in python?
    Ask us Anything! (66)
  • How do you print the first letter of each word in a string in python?
    Others (1,114)
  • How do you print the first letter of each word in a string in python?
    Mobile Development (46)

Subscribe to our Newsletter, and get personalized recommendations.

Already have an account? Sign in.

How do you find the first letter of each word in a string in python?

Get the first character of a string in python As indexing of characters in a string starts from 0, So to get the first character of a string pass the index position 0 in the [] operator i.e. It returned a copy of the first character in the string. You can use it to check its content or print it etc.

How do you get the first letter of each word in a string?

To get the first letter of each word in a string: Call the split() method on the string to get an array containing the words in the string. Call the map() method to iterate over the array and return the first letter of each word. Join the array of first letters into a string, using the join() method.

How do you print the first occurrence of a character in a string in python?

Use the find() Function to Find First Occurrence in Python We can use the find() function in Python to find the first occurrence of a substring inside a string. The find() function takes the substring as an input parameter and returns the first starting index of the substring inside the main string.

How do I print the first letter of a name in Python?

“how to print only the first letter in python” Code Answer's.
# Get First 3 character of a string in python..
first_chars = sample_str[0:3].
print('First 3 characters: ', first_chars).
# Output:.
First 3 characters: Hel..