Discuss / Python / f({})的使用

f({})的使用

Topic source

涵_天

#1 Created at ... [Delete] [Delete and Lock User]

在b站看的视频教程上,博主一直在用

name = 'xiaoming'
print(f'hello {name}!')

请问这也是一种格式吗 ,感觉这个更简单简洁

云剑决

#2 Created at ... [Delete] [Delete and Lock User]

python3.8新增的特性,用来格式化字符串的,和%s、format类似,,    不是编码

一般般188

#3 Created at ... [Delete] [Delete and Lock User]

就用f的格式了,确实方便简单。

name = "李四"

money = 123.456

day = 5

print("你好,{name}")

print(f"你好,{name},中奖¥{money:.2f}元")      # 还可以这样写!

print(f"你好,{name},中奖¥{54628.61458:.3f}元")

print(f"今天是:2020年{8:02d}月{day:3d}日")

小明-77

#4 Created at ... [Delete] [Delete and Lock User]

这种感觉会明晰很多,花括号倒是稍微麻烦一点。


  • 1

Reply