Python天天美味(7) - 连接字符串(join %)


join 方法用于连接字符串数组

= ['a''b''c''d']
print ''.join(s)
print '-'.join(s)

输出结果:
abcd
a-b-c-d

使用 % 连接多个变量

= 'hello'
= 'python'
= 1
print '%s %s %s %s' % (a, b, c, s)

输出结果:

hello python 1 ['a', 'b', 'c', 'd']


Python 天天美味系列(总)

Python 天天美味(5) - ljust rjust center  

Python 天天美味(6) - strip lstrip rstrip  

Python 天天美味(7) - 连接字符串(join %)  

Python 天天美味(8) - 字符串中的字符倒转

Python 天天美味(9) - translator

...

posted @   CoderZh  阅读(3903)  评论(3编辑  收藏  举报
编辑推荐:
· 如何在 .NET 中 使用 ANTLR4
· 后端思维之高并发处理方案
· 理解Rust引用及其生命周期标识(下)
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
阅读排行:
· Cursor预测程序员行业倒计时:CTO应做好50%裁员计划
· 想让你多爱自己一些的开源计时器
· 大模型 Token 究竟是啥:图解大模型Token
· 用99元买的服务器搭一套CI/CD系统
· 当职场成战场:降职、阴谋与一场硬碰硬的抗争
点击右上角即可分享
微信分享提示