Pythonエラー:AttributeError: 'NoneType'オブジェクトに属性がありません 'append'



Python Error Attributeerror



ソースプログラム:

''' Rewrite the program that prompts the user for a list of numbers and prints out the maximum and minimum of the numbers at the end when the user enters 'done'. Write the program to store the numbers the user enters in a list and use the max() and min() functions to compute the maximum and minimum numbers after the loop completes. ''' list = list() #Create an empty list while True: str = input('Enter a number: ') if str == 'Done': break try: num = float(str) except: print('You enter the wrong number!') quit() #print(num) list = list.append(num) print(list)

エラー:
トレースバック(最後の最後の呼び出し):
ファイル「E:/TESTS/PYTHON/list_ex_03/list_ex_03.py」、20行目
list = list.append(num)
AttributeError:「NoneType」オブジェクトに属性「append」がありません



理由:
list = list.append(num)、リスト自体を変更できるため、append()はリストを変更してNoneを返し、list = Noneはエラーを報告します。

解決:
次のように変更されます。



list.append(num)

大丈夫です。