import sys
import time
data = ["b","u","f","f","e","r","i","n","g"]
# display with one upper char
for x in range(len(data)):
# remeber lower char
old = data[x]
# replace with upper char
data[x] = old.upper()
# create full text
text = "".join(data)
# display full text
sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()
# put back lower char
data[x] = old
time.sleep(1)
# display without upper chars at the end
text = "".join(data)
sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()
data
如果你把额外的字符放在没有更高版本的末尾- 即。空字符串""
- 那么你不需要for
循环后的代码。
您也可以在开始时放置空字符串以显示不带大写字符的第一个文本。
import sys
import time
# text with extra chars at the start and at the end
data = ["", "b","u","f","f","e","r","i","n","g", ""]
# display with one upper char
for x in range(len(data)):
# remeber lower char
old = data[x]
# replace with upper char
data[x] = old.upper()
# create full text
text = "".join(data)
# display full text
sys.stdout.write("\r")
sys.stdout.write(text)
sys.stdout.flush()
# put back lower char
data[x] = old
time.sleep(1)