次の手順を実行する方法をより明確に説明します。 Pythonでインデックスの使用方法の理解
# loop while i is less than the length of name and the i-th character is not a space. # return the part of name up to but not including the i-th character to the caller.
def get_first_name(name):
i = 0
while i < len(name) and '' in str(i):
i += 1
return name
*「i番目の文字」*は、インデックス「i」の文字、つまり「名前[i]」です。 Pythonの文字列をインデックスで繰り返し処理するのは通常不要です。代わりに 'for char in name:'を使って各文字を取得することができます。 – jonrsharpe