Python remove () and Del statements distinguish and discriminate list delete operations

Source: Internet
Author: User
  • The del statement can delete the value at the bottom of the list, and all values following the deleted value in the table will move forward one subscript
Spam = [' A ', ' B ', ' C ', ' D ', ' E ']del spam[2]spam

Print display: [' A ', ' B ', ' D ', ' E ']

The DEL statement can also be used to delete a value in a variable, but it is rarely used in practice, and attempting to use the variable after deletion encounters a nameerror error

  • The Remove () method passes in a value that is removed from the list that is called.

  • Summary :

If you know the subscript of the list you want to delete, the DEL statement will be useful.

The Remove () method works well if you know the value that you want to remove from the list

Python remove () and Del statements distinguish and discriminate list delete operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.