python - 如何处理 f 字符串中的错误?

标签 python python-3.x error-handling f-string

我正在尝试处理 f 字符串中的错误,但我的尝试似乎不起作用。有办法实现吗?

string = f"For example I thought this syntax would work but it doesn't {try: 5/0 except Exception: str(infinity)}"

最佳答案

你不能。将异常处理移出 f 字符串。

关于python - 如何处理 f 字符串中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60688869/

相关文章:

python-3.x - AWS Lambda 函数 Boto 3 filter_log_events 无法使用 endTime 参数

python - Python import 是否将所有代码复制到文件中

Python,在带有变量的列表中查找项目

sql - SQLSTATE [23000] : Integrity constraint violation: 1048 Column 'status_member' cannot be null

php - 接收和处理无连接错误和200 OK header

Python:将打印递归函数转换为生成器

java - 找到两个线性等式成立的整数集

python - 如何基于周保存到 .csv 文件中

python - "if in"和 "if or if in"之间的差异;寻找解释

c# - 错误处理 MVC View 与 PartialView