小编Leo*_*Leo的帖子

为什么 print with end='' 直到新行才出现?

我一直在 python 3.9 中编写一个程序,并在获得以下代码后:

#Print 3 dots at the interval shown
def dots(t):
    t *= 3
    sleep(t)
    print('.', end='')
    sleep(t)
    print('.', end='')
    sleep(t)
    print('.')
Run Code Online (Sandbox Code Playgroud)

这称之为:

# These are completely aesthetic
sleep(0.25)
print("Defining Functions", end='')
dots(0.4)
Run Code Online (Sandbox Code Playgroud)

我预计程序会Defining Functions在 1.2 秒后打印 3 次,.在末尾添加一个点( )。真正发生的是 3.85 秒后,它用点 ( Defining Functions...) 打印了整个内容。因此,在添加新行(第三个点)之前它不会打印任何内容。

抱歉,如果有点乱,我不知道如何很好地提出这些问题

python newline python-3.x

6
推荐指数
1
解决办法
1793
查看次数

标签 统计

newline ×1

python ×1

python-3.x ×1