学习笔记(01):Python 面试100讲(基于Python3.x)-各种类型的变量与值之间的多种连接方式...

立即学习:https://edu.csdn.net/course/play/26755/340111?utm_source=blogtoedu

字符串和字符串之间的连接方式:5种

第一种:使用"+"(加号)

s1 ='hello'

s2='world'

s=s1+s2

print(s)

第二种:直接连接:

m="hello""world"

print(m)

第三种:使用","(逗号),标准输出重定向

from in import StringIO

import sys

old_std = sys.stdout

result = StringIO()

sys.stdout = result

print('hello','world')

sys.stdout=old_std

result_str = result.getvalue()

print(" 用逗号连接",result_str)

第四种:格式化

s='<%s><%s>' %(s1,s2)

print(s)

第五种:join

s=" ".join([s1,s2])

发布了4 篇原创文章 · 获赞 0 · 访问量 3213

猜你喜欢

转载自blog.csdn.net/zhaoxiaozheng1987/article/details/104245035