Python--关于连接符+
2016-06-30 15:33
393 查看
连接符 +
连接符 + 实则是创建了新的对象并占用新的内存(dict、set不能使用)
String
由于Python必须为每一个使用连接符+的字符串分配新的内存,并产生新的字符串。下面两种方式会更有效
①使用格式化操作符(%)
>>> '%s %s' % ('hello','world')
'hello world'
>>>
②将字符串放到列表中,使用join连接
>>> '_'.join(['hello','world'])
'hello_world'
>>>
list
同上,两个列表使用+连接是产生一个新的列表。可以是list.extend()来代替+
>>> p = [1,2,3]
>>> pp = [4,5,6]
>>> p.extend(pp)
>>> p
[1, 2, 3, 4, 5, 6]
>>>
相关文章推荐
- numpy 备忘录
- Python numpy函数hstack() vstack() stack() dstack() vsplit() concatenate()
- 发邮件自动回复本机IP——python版本
- python学习之unicode编码
- python使用MIMEMultipart发送多个附件的邮件
- Hinton's Dropout in 3 Lines of Python
- python flush使用
- Python:zip函数
- python 代码
- python内置函数
- 如何在Eclipse上搭建python环境
- python使用random函数生成随机数
- python之pexpect模块
- python操作csv
- python 生成验证码
- Python用户存储加密及登录验证系统(乞丐版)
- 贡献一段学习过程中的爬糗百的代码python
- Python--关于 join 和 split
- 如何基于Python构建一个可扩展的运维自动化平台
- Python 黑帽子 snffer ip header decoder