0

我的代码读取

import time
a = raw_input("Enter a string: ")
b = len(a)
#print 1st letter of string
time.sleep(2)
#print 2nd letter of string
#continue doing that until the last character in the string

我需要做什么才能让我的代码在 Python 2.7 中做到这一点?对正确方向的刺激将不胜感激。

谢谢你。

4

2 回答 2

1

您可以遍历字符串本身:

import time
a = raw_input("Enter a string: ")
for char in a:      #iterate over string one character at a time
   print char
   time.sleep(2)    # sleep after printing each character

例子:

>>> for x in "foobar":
...     print x
...     
f
o
o
b
a
r
于 2013-05-04T10:33:48.047 回答
0
In [1]: t = 'input string'

In [2]: for c in t:
   ...:     print c
   ...:     
i
n
p
u
t

s
t
r
i
n
g
于 2013-05-04T10:33:58.680 回答