python-for-data-and-media-communication-gitbook icon indicating copy to clipboard operation
python-for-data-and-media-communication-gitbook copied to clipboard

Some problems about return 'None'

Open MindyZHAOMinzhu opened this issue 5 years ago • 2 comments

Troubleshooting

使用list.remove之后return出来结果是None

Describe your environment

屏幕快照 2019-07-18 下午9 49 32 屏幕快照 2019-07-18 下午9 50 06
  • Operating system: Spyder
  • Python version: python3
  • Hardware: Mac
  • Jupyter notebook or not? [Y/N]: N
  • Which chapter of book?: the last exercise of Chapter 3

MindyZHAOMinzhu avatar Jul 18 '19 13:07 MindyZHAOMinzhu

@MindyZHAOMinzhu , you can use help(list.remove) to check the documentation. In short, this function is an "in-place" function, i.e. the operation is done in the original place referenced by the variable. In contrast, another type is call CoW (copy-on-write), i.e. the operation is done on a copy of the original data. So original data is kept intact when things are done. One CoW example is str.replace. Please try it out.

This is good question. We'll orgainise it into FAQ.

hupili avatar Jul 20 '19 14:07 hupili

A bit note:

  • in-place function -- is usually more efficient and saves computer memory
  • CoW -- is more secure/ less error-prone/ "functional" (no side effect)

hupili avatar Jul 20 '19 14:07 hupili