美文网首页
print(f"")与print('' '') 有什么不同?

print(f"")与print('' '') 有什么不同?

作者: James_Chu | 来源:发表于2019-08-19 15:57 被阅读0次

有没有小伙伴到现在还在用以下的%d%f%s ...等方式打印

'''age = int(input("Please input your age:"))

name = input("Please input your name:")

print("Ok,your name is %s, and your age is %d." % (name, age))'''

当然,也不是说这种方式不能用,但是我们有一种更加直观并且方便的用法--print(F”“)以下是改进后的代码。

'''age = int(input("Please input your age:"))

name = input("Please input your name:")

print(f"Ok,your name is {age}, and your age is {name}." )'''

这样写的话是不是比较方便,但一定要记住引号前的 f 一定不能忘记。

相关文章

网友评论

      本文标题:print(f"")与print('' '') 有什么不同?

      本文链接:https://www.haomeiwen.com/subject/otfesctx.html