我的代码是
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中做到这一点? 我们非常感谢正确方向的产品。
谢谢。
答案 0 :(得分: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
答案 1 :(得分: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