python - 在 Python 中的不同行中打印
问题描述
我试图在不同的行中打印以下代码,但它总是在同一行中打印。任何人都可以帮忙吗?
import time
import sys
def delay_print(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(0.05)
delay_print("Hi there hope everything is fine.")
time.sleep(2)
def delay_print(s):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(0.05)
delay_print("This is a mail.")
这是显示给我的输出-
Hi there hope everything is fine.This is a mail.
如何像这样打印它们-
Hi there hope everything is fine.
This is a mail.
解决方案
只需print("\n")
在 for 循环之后添加。
函数是在要多次完成特定任务时编写的,不需要声明相同的函数,只需调用它,你就可以开始了!
推荐阅读
- python - sqlalchemy.exc.IntegrityError: (pymysql.err.IntegrityError) (1062, "Duplicate entry '' " for key ""
- python - “手动”抛出的异常在 PowerShell ISE 中捕获,但不在命令行中
- python - 使用 unittest 框架测试 pandas 数据框
- performance - 我可以依赖 Google Lighthouse 报告(尤其是对于移动网站)吗?
- python - 我正在为这个 python 代码苦苦挣扎(我是初学者)
- javascript - 如何正确注释缓存的mixin
- azure - 从 Azure 帐户中删除所有资源
- c# - YamlDotNet - 自定义序列化
- node.js - NodeJS 中的动态导入(在 Gatsby 中):未指定动态导入回调
- reactjs - React hooks - 当我们刷新页面时从 react-router 位置状态中删除