Python 中是否有类似 Ruby 的 "Hello #{userName Function()}"
的东西?
最佳答案
在 Python 中,您将使用字符串插值
"Hello %s" % user_name_function()
或字符串格式化
"Hello {0}".format(user_name_function())
后者在 Python 2.6 或更高版本中可用。
另请注意,按照惯例,您不使用 CamelCase 作为 Python 中的函数名称(CamelCase 仅用于类名——参见 PEP 8)。
关于python - 字符串内求值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5282503/