日期:2023年3月3日
作者:Commas
签名:(ง •_•)ง 积跬步以致千里,积小流以成江海……
注释:如果您觉得有所帮助
,帮忙点个赞
,也可以关注我
,我们一起成长;如果有不对的地方,还望各位大佬不吝赐教,谢谢^ - ^
1.01365 = 37.7834;0.99365 = 0.0255
1.02365 = 1377.4083;0.98365 = 0.0006
前言:
在Python
中,你可以使用以下5种不同的方法来拼接字符串。
1、使用加号 + 操作符
str1 = "Hello"
str2 = "World"
result = str1 + " " + str2
print(result) # 输出:Hello World
2、使用 str.join() 方法:
str_list = ["Hello", "World"]
result = " ".join(str_list)
print(result) # 输出:Hello World
3、使用 f-字符串
温馨提示:Python 3.6及更高版本。
str1 = "Hello"
str2 = "World"
result = f"{str1} {str2}"
print(result) # 输出:Hello World
4、使用字符串格式化
str1 = "Hello"
str2 = "World"
result = "{} {}".format(str1, str2)
print(result) # 输出:Hello World
5、使用 % 运算符
温馨提示:不推荐,Python 3.6之后,推荐使用f-字符串或字符串格式化。
str1 = "Hello"
str2 = "World"
result = "%s %s" % (str1, str2)
print(result) # 输出:Hello World
版权声明:本文为博主原创文章,如需转载,请给出:
原文链接:https://blog.youkuaiyun.com/qq_35844043/article/details/134009776