繁体   English   中英

格式化字符串地狱 - Python

[英]Formatted string hell - Python

x = f'{1}{2}{3}'

a = "one"
b = "two"
c = "three"

#I want to print "onetwothree"

我什至不知道如何解释这个问题,每次我开始在谷歌中输入任何内容时,我都愣住了。 还没有尝试任何东西,因为我什至不知道从哪里开始。 帮助。

您可以在 f 字符串的括号内插入变量的名称。

a = "one"
b = "two"
c = "three"

print(f'{a}{b}{c}')
>>> onetwothree

将变量名称放入 f 字符串中。

print(f"{a}{b}{c}")
x = f'{1}{2}{3}'

a = "one"
b = "two"
c = "three"

#I want to print "onetwothree"
print(f"{a}{b}{c}")

在此处输入图像描述

说明:对于每个变量x ,您填写{x} 对于 python 3,如果要打印项目,请使用print(item) function。

print() function 将指定的消息打印到屏幕或其他标准 output 设备。 消息可以是字符串,也可以是其他任何 object,object 会在写入屏幕之前转换为字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM