How to allow list append() method to return the new list

前端 未结 7 1591
春和景丽
春和景丽 2020-12-09 00:31

I want to do something like this:

myList = [10,20,30]
yourList = myList.append (40)

Unfortunately, list append does not return the modified

7条回答
  •  粉色の甜心
    2020-12-09 01:06

    Just to expand on Storstamp's answer

    You only need to do myList.append(40)

    It will append it to the original list,now you can return the variable containing the original list.

    If you are working with very large lists this is the way to go.

提交回复
热议问题