Skip to content
How do we print letters by letters in python?
Profile icon
Dazz

Hi, I am actually a beginner in python.I am trying to do some small project and I want to decorate it.So I was thinking that could python print words letter by letter?

Thanks very much if someone could help me with this.

You are viewing a single comment. View All
Profile icon
CodingCactus

hi,

@Dazz
, what i am giving you is all
@xolyon
's, so credit them, not me, but i may as well give it to you any way.

import sys def scrollTxt(text): for char in text: sys.stdout.write(char) sys.stdout.flush() sleep(0.05)

to use it, just replace the normal print("words"), with scrollTxt("words")

Profile icon
Dazz
Profile icon
Dazz

@CodingCactus
Is input("Words") also the same?

Profile icon
CodingCactus

@Dazz
yes, i thing do scrollTxt(input("words"))

Profile icon
xolyon

@Dazz
btw you can add your own time parameter to get out text as slowly/quickly as you wan , also if you just want this nor ally , get rid of the for loop and replace char with text

also to this but itself just do

import sys sys.stdout.write("something")

to use this for the input you may have to change the code around a bit so that it returns instead of prints

or upu can just put the input below :)

Profile icon
CodeLongAndPros

@CodingCactus
In python3 you should do

for c in string: print(c, end="") time.sleep(0.5)
Profile icon
CodingCactus

@CodeLongAndPros
oh, what I (xolyon) said sill works tho

Profile icon
Aqtion

Also is it alright if i used this too because I really like this feature.

@CodingCactus
@xoloyon

Profile icon
CodingCactus

@kbadrinath_tcsp it's xolyons, i saw it used on your post recently

Profile icon
Aqtion

oh yeah, so can you ask

@xoloyon
if I can use it? I'll take it off my post until I have your permission.
@CodingCactus

Profile icon
CodingCactus

@kbadrinath_tcsp i assume they'll yet you use it, they let me use and they seem nice :)