我不明白
以下是我所做的研究:
我正在看的文件:
文档
我特别要看这一段:
class list([iterable]) Return a list whose items are the same and in
the same order as iterable’s items. iterable may be either a sequence,
a container that supports iteration, or an iterator object. If
iterable is already a list, a copy is made and returned, similar to
iterable[:]. For instance, list('abc') returns ['a', 'b', 'c'] and
list( (1, 2, 3) ) returns [1, 2, 3]. If no argument is given, returns
a new empty list, [].list is a mutable sequence type, as documented in Sequence Types —
str, unicode, list, tuple, bytearray, buffer, xrange. For other
containers see the built in dict, set, and tuple classes, and the
collections module.
这里是另一个帖子:
另一篇关于list函数的文章
在这个帖子上,有人发布了以下内容:
1 2 3 4 | >>> myList = ['hello'] >>> myList=list(myList[0]) >>> myList ['h', 'e', 'l', 'l', 'o'] |
但当我这样做的时候:
1 2 3 4 5 6 7 8 9 10 11 12 13 | for root, dirs, files in os.walk(os.getcwd()): path_files.append(files) path_files [['combinedPdfs.py', 'meetingminutes.pdf', 'meetingminutes_encrypted.pdf', 'pdf_intro.py', 'pdf_paranoia.py', 'readDocx.py']] >>> path_files_2 = list(path_files[0]) >>> path_files_2 ['combinedPdfs.py', 'meetingminutes.pdf', 'meetingminutes_encrypted.pdf', 'pdf_intro.py', 'pdf_paranoia.py', 'readDocx.py'] >>> path_files_2[0] 'combinedPdfs.py' >>> path_files_2[1] 'meetingminutes.pdf' |
为什么我所做的工作与其他帖子的用户不同?
编辑# 1:
如果我这样运行:
1 2 3 4 5 6 7 8 9 | >>> myList2 = ['hello', 'goodbye'] >>> myList2[0] 'hello' >>> myList2 = list(myList2) >>> myList2 ['hello', 'goodbye'] >>> myList2 = list(myList2[0]) >>> myList2 ['h', 'e', 'l', 'l', 'o'] |
如果我这样运行:
1 2 3 4 5 6 7 | >>> myList4 = [['Hello', 'goodbye']] >>> myList4 = list(myList4) >>> myList4 [['Hello', 'goodbye']] >>> myList4 = list(myList4[0]) >>> myList4 ['Hello', 'goodbye'] |
我看到了这个定义,但我希望有一个更"门外汉"的方式来解释它。
使用名为
命令
虽然我看不出您在哪里定义了
我通常不认为它是"列表函数",而是"列表数据类型",它有自己的方法。当您键入