Discuss / Python / 作业

作业

Topic source

L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa'] ]

lists=[L[0][0],L[1][1],L[2][2]] for list in lists: print(list)

结果是对的,请问for list in lists:是什么原理啊?还有print(list)前的4个空格是什么意思呢?为什么这样打印出来的3个名字会自动转行?

Yehson

#3 Created at ... [Delete] [Delete and Lock User]

按执行顺序,先执行lists,再给list赋值为lists,所以执行list,等于执行lists,然后输出lists的内容。

看来还是有些来复习基础的啊。我就一啥也不懂的太白

L = [ ['Apple', 'Google', 'Microsoft'], ['Java', 'Python', 'Ruby', 'PHP'], ['Adam', 'Bart', 'Lisa'] ]

print(L[0][0])

print(L[1][1]) print(L[2][2])

DIDADI201306

#6 Created at ... [Delete] [Delete and Lock User]

L = [ ... ['Apple', 'Google', 'Microsoft'], ... ['Java', 'Python', 'Ruby', 'PHP'], ... ['Adam', 'Bart', 'Lisa'] ... ] lists=[L[0][0],L[1][1],L[2][2]] for list in lists: ... print(list) File "<stdin>", line 2 print(list) ^ IndentationError: expected an indented block

求解

DIDADI201306

#7 Created at ... [Delete] [Delete and Lock User]

for list in lists: 我这句执行不过去呢?不加这句可以直接打印list

沧澜428

#8 Created at ... [Delete] [Delete and Lock User]

@DIDADI201306,你是不是哪个标点弄错了?


  • 1

Reply