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

cal*_*pto 1 python error-handling python-3.x f-string

我正在尝试处理 f 字符串中的错误,但我的尝试似乎不起作用。有没有办法做到这一点?

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

use*_*ica 9

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