Python list Knowledge points explained

Source: Internet
Author: User
Tags python list
Change and delete

Increase

The X.append function is to append a new element to the list at the end of the original list

X.extend () Adds a list of elements to another list, keeps the referenced original list intact, and extend can also be applied to tuples, dictionaries, collections ...

X.insert (subscript, Element) insert adds an element at a specified position based on the subscript

By deleting:

X.remove ("content") add a specific element to delete, only 1 elements can be deleted at a time, if a list of multiple duplicate elements, will be deleted from left to right found the first element to meet the deletion criteria

X.pop (subscript) deletes the element corresponding to the subscript according to the list subscript and returns the value of the deleted element (the return value needs to be received using the variable)

Del x[0] del can delete an element based on the slice subscript in the list, and Del clears all elements of the entire list if it is not given the subscript to be deleted.

X.clear () empties the entire list so that the list element value is empty

Change:

x[0]= "One" modifies or replaces elements in a list, which can be replaced and modified in the form of a slice assignment

Check:

X.index () returns the subscript based on the element, if multiple repeating elements appear in the list, the first element that is found from left to right is returned subscript

In/not in

Finds whether an element exists in the list or does not exist, the return value is a Boolean value Ture/false

COUNT () query the number of duplicates in an element in the list

Python list Knowledge points explained

Related Article

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.