Methods of List Object in Python
[] is the symbol we use in Python to create a list.
A list can hold multiple items of any type (numbers, strings, even other lists) and we can add, remove, or access items using their position (index).
List has some built-in Methods because it’s an object, the ones you often use are methods like:
-
append()– add an item to the end of the list -
extend()– add multiple items at once -
insert()– insert item at a specific position -
remove()– remove a specific item -
pop()– remove item by index -
sort()– sort the list -
reverse()– reverse the list -
count()– count how many times a value appears -
index()– find index of a value
Comments
Post a Comment