2006年01月15日 星期日 11:40
Robert Chen,您好!
在这个BLOG的评论里,有:
s = ','.join('str1', 'str2', 'str3')
这个句子,我怎么运行不了,报错误:
Traceback (most recent call last):
File "", line 1, in ?
TypeError: join() takes exactly one argument (3 given)
在 2006-01-15 08:43:00 您写道:
>关于"+"操作符和join操作比较,可以参考《Python源码剖析》中的这篇关于字符串对象的文章:
>http://blog.donews.com/lemur/archive/2005/12/22/667710.aspx
>
>
>On 1/15/06, yzhh <yezonghui at gmail.com> wrote:
>>
>> python中string是immutable,所以下面的代码感觉效率有些低
>> for i in xrange(1000):
>> s = s + 'something'
>> 因为创建了和销毁了1000个string
>>
>> 能不能先做个够大的buffer,然后修改之,最后转换成string,好像
>> l = []*1000*9 # len('something') == 9
>> for i in xrange(1000): l[i*9:(i+1)*9] = 'something'
>> s = ''.join(l)
>> 但是上面这个join()不是为这个目的做的,不知道效率是不是也一样低?
>> 或者join()就是为这个目的做的,我想错了?
>>
>> --
>> regards,
>> yzhh
>>
>> _______________________________________________
>> python-chinese
>> Post: send python-chinese at lists.python.cn
>> Subscribe: send subscribe to python-chinese-request at lists.python.cn
>> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
>> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>>
>_______________________________________________
>python-chinese
>Post: send python-chinese at lists.python.cn
>Subscribe: send subscribe to python-chinese-request at lists.python.cn
>Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
>Detail Info: http://python.cn/mailman/listinfo/python-chinese
致
礼!
cry
zyqmail at tom.com
2006年01月15日 星期日 11:45
','.join(['str1','str2','str3']) 或者 ','.join(('str1','str2','str3'))
--
开飞机的舒克
http://www.lvye.org/shuke
msn:weizhong at netease.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060115/d66390ea/attachment.html
Zeuux © 2025
京ICP备05028076号