for循环中的语法是什么意思?Python for循环的语法为什么
我特别迷茫什么是
for X
在下面的例子,为什么我使用“字母”是什么意思?是否因为'函数'是函数执行时我想返回的东西的单个组件?
我花了几个小时在函数内切换单词'letter','line','row'和'row_index'的位置以获得有效的工作。
我必须写作为一项任务的每一个函数,我都有同样的困惑。
def make_str_from_row(board, row_index):
""" (list of list of str, int) -> str
Return the characters from the row of the board with index row_index
as a single string.
>>> make_str_from_row([['A', 'N', 'T', 'T'], ['X', 'S', 'O', 'B']], 0)
'ANTT'
"""
line = ''
for letter in board[row_index]:
line = line + letter
return line
为字母,打印信件中的每个字母。 '在“abcdef ...”中输入字母:print(letter)' – Li357
https://opentechschool.github.io/python-beginners/en/loops.html – Alexander
您可以使用'line + = letter'作为短手对于'line = line + letter'。另外我认为值得一提的是,这个方法可以用'''.join(board [row_index])'来完成。它会加入board [row_index]的每个字母,在每个字母之间加上''''(无)。 – Alexander