Skip to content
Sign UpLog In
This post is read-only. Explore Repls and connect with other creators on Community.View Community
The info in this post might be out of date, check out our docs instead. View docs
1

How to print 1 letter at a time.

OldWizard209
OldWizard209

Hi, I want to print one letter at a time with an interval of 0.3 seconds on the same line. How am I supposed to implement it in my program. I appreciate your kind help.

2 years ago
You are viewing a single comment. View All
2
Bookie0
Bookie0

Hi,

here is a better way of doing it:

First the imports:

import sys, os import time

And this is the code:

st = 0.03 def sp(str): for letter in str: sys.stdout.write(letter) sys.stdout.flush() time.sleep(st) print()

I usually put it at 0.04 because it prints it not too fast and not too slow. But you can change it. Just change the value after st

Each time you want to do this typewriter effect, just do:

sp(“Hello World”)

Output:

Hello World

(outputted one char at a time)

this is from my tutorial here ;)

2 years ago
2
OldWizard209
OldWizard209

OH Thanks a lot for the help

@Bookie0
I will try this method. But sorry I couldn't mark your answer. :)

2 years ago
2
Bookie0
Bookie0

np lol :D

@abdullahrajput9
putting it in a function is easier so you can use it when you need/want to! :)

2 years ago
1
RYANTADIPARTHI
RYANTADIPARTHI

@Bookie0
well, i guess this is good, but I did it in fewer lines of code. That matters.

2 years ago
1
Bookie0
Bookie0

@RYANTADIPARTHI
but then to use it several times...?

2 years ago