Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';非类型';对象没有属性';追加';在循环中附加到列表时_Python_Python 3.x_List_Append - Fatal编程技术网

Python ';非类型';对象没有属性';追加';在循环中附加到列表时

Python ';非类型';对象没有属性';追加';在循环中附加到列表时,python,python-3.x,list,append,Python,Python 3.x,List,Append,我一直收到以下错误消息: Traceback (most recent call last): File "C:/Users/tabba/PycharmProjects/erle_loops/Hobbies.py", line 9, in <module> hobbies = hobbies.append(hobby) AttributeError: 'NoneType' object has no attribute 'append' 回溯(最近一

我一直收到以下错误消息:

Traceback (most recent call last):
  File "C:/Users/tabba/PycharmProjects/erle_loops/Hobbies.py", line 9, in <module>
    hobbies = hobbies.append(hobby)
AttributeError: 'NoneType' object has no attribute 'append'
回溯(最近一次呼叫最后一次):
文件“C:/Users/tabba/PycharmProjects/erle_loops/cabiods.py”,第9行,在
嗜好=嗜好。附加(嗜好)
AttributeError:“非类型”对象没有属性“附加”
本程序的目的是将爱好添加到列表中

我的代码:

hobby = ''
hobbies = []
no_room_left = False
room = 3
count = 0
while not no_room_left:
    if count<room:
        hobby = str(input("Enter hobby"))
        hobbies = hobbies.append(hobby)
        count+=1
print(hobbies)
hobby=''
爱好=[]
没有剩余房间=错误
房间=3
计数=0
虽然没有剩余的空间:
如果count返回
None
并更改列表,那么请自行使用
append
(不应设置):

代码:

hobby=''
爱好=[]
没有剩余房间=错误
房间=3
计数=0
虽然没有剩余的空间:
如果算上
# List would be None
hobbies = hobbies.append(hobby)

# Good
hobbies.append(hobby)
hobby = ''
hobbies = []
no_room_left = False
room = 3
count = 0
while not no_room_left:
    if count<room:
        hobby = str(input("Enter hobby"))
        hobbies.append(hobby)
        count+=1
print(hobbies)