print(f““)与print(‘‘ ‘‘) 的不同之处

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

  • 原文链接: https://www.jianshu.com/p/1ec0e30fdf1d
    有没有小伙伴到现在还在用以下的%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 一定不能忘记。

你可能感兴趣的:(python)