关于join的一些补充

1, 为什么join是string的method而不是list的method

http://effbot.org/pyfaq/why-is-join-a-string-method-instead-of-a-list-or-tuple-method.htm

2, join的语法

>>> params = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
>>> ["%s=%s" % (k, v) for k, v in params.items()]
['server=mpilgrim', 'uid=sa', 'database=master', 'pwd=secret']
>>> ";".join(["%s=%s" % (k, v) for k, v in params.items()])
'server=mpilgrim;uid=sa;database=master;pwd=secret'

http://www.diveintopython.net/native_data_types/joining_lists.html

posted on 2017-12-19 16:20  freshair_cn  阅读(194)  评论(0编辑  收藏  举报

导航