python两列字符串若何兼并?
python两列字符串兼并的办法:
一、正在不少状况下,咱们都需求兼并字符串。例如:需求将姓氏与名字存储正在没有同的变量中,而后显示的时分再将他们合二为一
first_name = 'oliver' last_name = 'smith' full_name = first_name + ' ' + last_name print(full_name)
打印后果:
oliver smith
二、python中应用(+)号来兼并字符串
这类字符串兼并的办法称为拼接,可以使用存储正在变量中的信息来创立完好的信息
first_name = 'oliver' last_name = 'smith' full_name = first_name + ' ' + last_name print('Hello ' + full_name.title() + '!')
打印后果:
Hello Oliver Smith!
此处的title()办法将单词的首字母年夜写了,让姓名显示更格局化
三、也能够创立用一个变量来存储整条语句
first_name = 'oliver' last_name = 'smith' full_name = first_name + ' ' + last_name msg = 'Hello ' + full_name +'!'print(msg)
这样,print语句中显示的就没那末复杂了!
保举教程:《python视频教程》
以上就是python两列字符串若何兼并?的具体内容,更多请存眷资源魔其它相干文章!
标签: 字符串 Python python教程 python编程 python使用问题
版权声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。
抱歉,评论功能暂时关闭!