- Mastering Python Scripting for System Administrators
- Ganesh Sanjiv Naik
- 76字
- 2021-07-02 14:00:23
Deleting list elements
To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting. You can use the remove() method if you do not know exactly which items to delete. Refer to the following example:
#!/usr/bin/python3
cities = ['Mumbai', 'Bangalore', 'Chennai', 'Pune']
print ("Before deleting: ", cities)
del cities[2]
print ("After deleting: ", cities)
Output:
Before deleting: ['Mumbai', 'Bangalore', 'Chennai', 'Pune']
After deleting: ['Mumbai', 'Bangalore', 'Pune']
推薦閱讀
- Apache ZooKeeper Essentials
- Android Studio Essentials
- JIRA 7 Administration Cookbook(Second Edition)
- Learning Linux Binary Analysis
- Flash CS6中文版應(yīng)用教程(第三版)
- 精通網(wǎng)絡(luò)視頻核心開(kāi)發(fā)技術(shù)
- Java Web開(kāi)發(fā)詳解
- Scala for Machine Learning(Second Edition)
- 遠(yuǎn)方:兩位持續(xù)創(chuàng)業(yè)者的點(diǎn)滴思考
- 愛(ài)上C語(yǔ)言:C KISS
- Instant Apache Camel Messaging System
- Mastering VMware Horizon 7(Second Edition)
- Anaconda數(shù)據(jù)科學(xué)實(shí)戰(zhàn)
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- WebStorm Essentials