如何在Python中连接两个字符串以转换为单个字符串?
要在Python中连接2个字符串,我们可以使用串联运算符'+'。例如:
str1 = "Hello" str2 = "World" str3 = str1 + str2 print str3
这将给我们输出:
HelloWorld
我们还可以使用str.join(seq)将多个字符串连接在一起。例如:
s = "-";
seq = ("a", "b", "c"); # This is sequence of strings.
print s.join( seq )这将给我们输出:
a-b-c
请注意,将字符串连接在一起时,我们给出的str用作分隔符。
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短