我如何在 python2.7 之间没有 space 的情况下逐个字符打印字符串?

How can i print string one by character without space between them IN python2.7?

当我在一行中一个一个地打印字符串时,space 自动发生。他们之间!!

import time
a="mayank"
for z in a:
    time.sleep(0.1)
    print z,

m a y a n k

但我想打印它们时中间没有 spaces!! 喜欢:-

mayank

在python2.7

你可以这样做:

from __future__ import print_function
print(z, end='')

另一个选项:

import sys
sys.stdout.write(z)

如果您的 Python 是 运行 缓冲 ​​io,您可能在写入换行符之前看不到任何输出。在这种情况下,您可以通过添加对 sys.stdout.flush() 的调用来强制立即写入输出。

尝试:

import time
a="mayank"
for z in a:
    time.sleep(0.1)
    print (z, end="")