python-for-data-and-media-communication-gitbook
python-for-data-and-media-communication-gitbook copied to clipboard
Some problems about return 'None'
Troubleshooting
使用list.remove之后return出来结果是None
Describe your environment


- 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 , 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.
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)