0% found this document useful (0 votes)
4 views1 page

Python List Functions

Uploaded by

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

Python List Functions

Uploaded by

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

Python List Functions / Methods

Function / Method Description Example

append(x) Adds an element at the end fruits.append("orange")

insert(i, x) Inserts element at index i fruits.insert(1, "mango")

extend(iterable) Adds multiple elements fruits.extend(["kiwi","grape"])

remove(x) Removes first occurrence of value fruits.remove("banana")

pop([i]) Removes & returns element (last by default) fruits.pop()

clear() Removes all elements fruits.clear()

index(x) Returns index of first occurrence fruits.index("apple")

count(x) Counts how many times a value occurs fruits.count("apple")

sort() Sorts the list in ascending order fruits.sort()

reverse() Reverses the order of list fruits.reverse()

copy() Returns a shallow copy new_list = fruits.copy()

len(list) Returns number of elements len(fruits)

sum(list) Returns sum of numeric elements sum([1,2,3]) → 6

max(list) Returns largest element max([4,7,1]) → 7

min(list) Returns smallest element min([4,7,1]) → 1

sorted(list) Returns new sorted list sorted([3,1,2]) → [1,2,3]

You might also like