- 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']
推薦閱讀
- ASP.NET Core:Cloud-ready,Enterprise Web Application Development
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 深入淺出Java虛擬機:JVM原理與實戰
- Visual Basic程序設計教程
- Web全棧工程師的自我修養
- 精通網絡視頻核心開發技術
- Java EE 8 Application Development
- 零基礎Java學習筆記
- C# and .NET Core Test Driven Development
- Troubleshooting Citrix XenApp?
- Node.js區塊鏈開發
- scikit-learn Cookbook(Second Edition)
- jQuery Mobile Web Development Essentials(Second Edition)
- Java自然語言處理(原書第2版)