0% found this document useful (0 votes)
16 views2 pages

List Python

The document outlines various methods for manipulating lists in Python, including appending, inserting, and removing items. It also describes how to sort, reverse, and copy lists, along with examples for each method. Key methods include append(), insert(), remove(), pop(), clear(), reverse(), sort(), and copy().

Uploaded by

zahidzafeer3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views2 pages

List Python

The document outlines various methods for manipulating lists in Python, including appending, inserting, and removing items. It also describes how to sort, reverse, and copy lists, along with examples for each method. Key methods include append(), insert(), remove(), pop(), clear(), reverse(), sort(), and copy().

Uploaded by

zahidzafeer3
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Arrays [list] Methods For Python

1. append( ) method
to append an item to the end of the list
for example,
[Link]("color")

[Link]( ) method
to insert an item at any place in a list
for example,
[Link]'(1, "color")

3. extend( )
to append elements from another list
for example if you want to extend the thislist to hold values of mylist then,
[Link](mylist)

4. remove( ) method
to remove a specified item in a list
for example,
[Link]("banana") #the remove fucntion can only remove the
first instance of a given item duplicate remains.

5. pop( ) method
to remove a specified item with respect to it's index
for example,
[Link](1)

6. del method
to delete the whole list
for example,
del thislist

7. clear( ) method
to clear or empty the whole list
for example,
[Link]( )

8. reverse ( ) method
to reverse the order of the list
for example,
[Link]

9. sort ( ) method
sort the list ascending by default
forexample, # capital letters are always
written first, if the list contain [a, Z, e, c)
[Link]( ) # gives the list [ Z,a, c, e]
eventhough the desired result was [a, c, e, Z]

10. sort (key = [Link]) method


case-insensitive sorting
forexample,
[Link](key = [Link]) # this does give the result as [a, c, e, Z]

11. sort (reverse = True ) method


sort the list descendingly
for exampe,
[Link](reverse = True)
12. copy ( ) method
copy the contents of list to another list
for example,
thislist = [Link]( )

You might also like