1

我正在使用以下

clear= join(('string', seed ,'Aviesta'));

它给了我错误:未定义全局名称“加入”。请帮助!

4

1 回答 1

7

join是一个str方法,你需要在一个str实例上调用它:

In [31]: str.join??
Type:       method_descriptor
String Form:<method 'join' of 'str' objects>
Namespace:  Python builtin
Docstring:
S.join(iterable) -> string

Return a string which is the concatenation of the strings in the
iterable.  The separator between elements is S.

In [32]: ''.join(('string', 'seed' ,'Aviesta'))
Out[32]: 'stringseedAviesta'

In [33]: '_'.join(('string', 'seed' ,'Aviesta'))
Out[33]: 'string_seed_Aviesta'
于 2013-02-14T06:10:30.430 回答