Python 中没有 `printf` 函数,但是有类似的功能,它使用 `print` 函数和格式化字符串来实现。在 Python 中,你可以使用 `%` 符号作为格式化字符串的开始,后面跟格式化说明符来指定值的格式。格式化说明符包括 `%s`(字符串)、`%d`(整数)、`%f`(浮点数)等。
例如,在 Python 3 中,你可以这样使用格式化输出:
print("Hello, %s!" % "World")
或者使用更现代的格式化方法:
print("Hello, {}!".format("World"))
或者使用 f-string(Python 3.6 及以上版本支持):
print(f"Hello, {\"World\"}!")
这些方法都能实现类似 C 语言中 `printf` 的功能,在控制台输出格式化的内容