How do I print the first letter of a word?

how to print the first letter of a word in python
print first letter of every word in the string java
how to print the first character of a string in c
how to print each character of a string in python
python print the first letter of each word in the phrase
how to print a word letter by letter in python
python first character of word
python first letter of sentence

I looked through other problems and they don't seem to be helpful for me, so I decided to ask.

My code has created a random variable from my file (NECESSARY) I want to print the string that comes with my variable, but I only want it to print the first letter of the string.

E.G. It is a song name like "Cheese", I only want "C?????" to be printed but I am not sure how to tackle this problem as I am a new coder.

I have tried to have the word in the string alone, as before hand it has the Artist name with it but I removed it so it is just 1 word as it can be split easier for a beginner.

import random

EFile=open("ExternalFile.txt","w+")

Info1=("Shotgun")
Info2=("God's Plan")
Info3=("This is me")
Info4=("Solo")
Info5=("Psyco")

EFile.write(Info1)
EFile.write(Info2)
EFile.write(Info3)
EFile.write(Info4)
EFile.write(Info5)
EFile.close

Array=[Info1, Info2, Info3, Info4, Info5]

RanVar=random.choice(Array)
print(RanVar)

This part of the code works well, and it chooses one of the variables at random, but I need the strings attacked to the variables 'Info' to only print the first letter, and if possible, print the rest of the words as question marks.

If that is too complex for a beginner, I would like it to just be the first letter.

You can just write the first letter using RanVar[0] and then the rest by writing "?" 1 less time than the total length of RanVar using the code '?'*(len(RanVar)-1). Then you just concatenate these together with +

import random
Info1=("Shotgun")
Info2=("God's Plan")
Info3=("This is me")
Info4=("Solo")
Info5=("Psyco")

Array=[Info1, Info2, Info3, Info4, Info5]

RanVar=random.choice(Array)
print(RanVar[0]+'?'*(len(RanVar)-1))

Extract first character of each word from the sentence string, Try something like this: line = "I like to play guitar and piano and drums" words = line.split() letters = [word[0] for word in words] print  You want to create a list first, and then add the first letter to the list on every pass through the for. The first search result when you Google, ‘python adding to a list’, is an official doc by Google titled, “ Python Lists ”.

Approach 1# using for loop

content=["Shotgun","God's Plan","This is me","Solo","Psyco"]
chars=[]
for y in content:
    chars.append(y[0])
print(chars)

Approach 2# list comprehension

content=["Shotgun","God's Plan","This is me","Solo","Psyco"]
chars=[y[0] for y in content ]
print(chars)

Print the first and last character of each word in a String , Function to print the first. // and last character of each word. void FirstAndLast(​string str). {. int i;. for (i = 0; i < str.length(); i++). {. // If it is the first word. // of the string  So far all I can do is split the sentence into the separate words: import string def main(): print "This program splits the words in a sentence" print p = raw_input("Enter a sentence: ") words = string.split(p) print "The split words are:", words main() Thanks for any help!

Python treats every string as an array. you can print the letters with their index. The code below can be even simpler (I made it easy to select which letter to print)

import random

EFile=open("ExternalFile.txt","w+")
Info = ["Shotgun","God's Plan","This is me","Solo","Psyco"]
for w in Info:
    EFile.write(w)
EFile.close

RanVar=random.choice(Info)

for i, letter in enumerate(RanVar):
    if i == 0:
        print (letter, end ="")
    else:
        print ('?', end ="")

print ('\n')

String containing first letter of every word in a given string with , Print last character of each word in a string · Calculate the frequency of each word in the given string. Improved By : 29AjayKumar, princiraj1992, Rajput-Ji,  I was told that I could print letter and legal simultaneously, but it only recognizes one size at a time. If a document has both letter and legal sizes, I need it to recognize which size to print. In other words, pages 1-20 might be letter size, page 22-25, legal size and then the next ones letter and so on.

Strings, print letter a. For most people, the first letter of 'banana' is b, not a. But in word = 'banana' count = 0 for letter in word: if letter == 'a': count = count + 1 print count However, there's another part where it takes the first letter of each string in the list and prints it out in capital letters in one line. I cannot figure out how to print this on one line. This is my code:

How to print first character of each word in upper case of a string in , 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  here is raw file of program for you to copy and run it yourself. remember I haven’t included field checking so provide english alphabets only. #include <stdio.h>; #include &lt;string.h&gt; int main() { int isSpaceFound=0; int i=1,len=0; char str[100]; pr

Print first letter of each word in a string in C#, string[] strSplit = str.Split();. Now, loop through each word and use the substring method to display the first letter as shown in the following code  The most common thing to mail-merge is the standard, annoying form letter, which you can then print and ship out. 1 Start a new, blank document. You can use the keyboard shortcut Ctrl+N. 2 On the Mailings tab, from the Start Mail Merge group, choose Start Mail Merge→Letters.

Comments
  • Use string[i] to access the character of string at index i. Also see slicing.
  • Not sure to get your question, but if you want to print the string you can do it this way : print(myvar[0]+'?'*(len(myvar)-1))
  • I am l literally brand new to coding so this is immensely confusing to me sometimes.
  • I just want to print the first letter of the string, so it only shows E.G. S from Shotgun
  • I tried this and it didn't print the amount of question marks equivalent to the amount of characters in the string. Any idea?
  • @LordDoe Are you sure? it worked for me
  • It's just that "Shotgun" and "Solo" have the same 1st letter: S.
  • I disagree with the fact you specify end="" at the end of the word, if this is a guess game, the op will probably need to print things after that ^^
  • Changed as requested (although I think it's obvious enough?)
  • We never know ! :p