网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

f-string怎么格式转化

时间:2024-10-13 05:49:56

1、animal = "dog"print(f"There is a {animal}.")基本的格式就是f后面街上字符串,然后用大括号括如变量。

f-string怎么格式转化

2、lucky = 88print(f"The lucky number is {lucky}.")不只是字符串,还可以接入数字。

f-string怎么格式转化

3、lucky = 88print(f"The lucky number is {lucky + 12}.")实际上只要语法不出错,这个大括号里面是可以进行运算的。

f-string怎么格式转化

4、print(f"The lucky number is {666}.")那么如果没有变量的话,也是可以直接传入数据的。

f-string怎么格式转化

5、print(f"The lucky number is {{666}}.")如果需要输出大括号,那么我们需要再加一个大括号。

f-string怎么格式转化

6、print(f"The lucky number is {{666}}.\ The other number is {lucky}")如果要转行,那么只需要用反斜杠即可。

f-string怎么格式转化
© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com