Methods and Functions

Python List Methods

Python list methods are a set of built-in methods that can be implemented on the lists. The Python list methods can be used according to the convenience of the user. 

python list methods

Source

What are the list methods in Python?

There are various built-in Python list methods used for different purposes. These are mentioned below:

  1. append()-the append() is used to add an element to the end of the list.
  2. clear()- this function removes all the elements present in the list
  3. copy()- this function returns a copy of the list as requested by the user
  4. count()- this function counts and then returns the number of elements present in the list
  5. extend()- this function adds the elements present in a list or any iterable, to the end of the current list
  6. index()- this function returns the value of the index of the first element
  7. insert()- this function adds an element at the specified position mentioned by the user
  8. pop()- this function removes the element specified by the user at a given index.
  9. remove()- this function removes the value of a specified item mentioned by the user
  10. reverse()- this function reverses the order of the list given by the user.
  11. sort()- this function sorts the list given by the user

How do I see methods in Python?

The help command function in Python allows users to see a list of all the methods. This function allows the user to see all of the key methods connected with a particular object.

Another method to list all the methods of a class is by using the dir() in Python. The dir() returns all the properties and the functions related to a class.

For example:

                    

import random

 

print("The random library's contents are as follows:")

 

print(dir(random))



Output : 

The random library's contents are as follows:


['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST',

'SystemRandom', 'TWOPI', '_BuiltinMethodType', '_MethodType', '_Sequence',

'_Set', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__',

'__name__', '__package__', '__spec__', '_acos', '_ceil', '_cos', '_e', '_exp',

'_inst', '_log', '_pi', '_random', '_sha512', '_sin', '_sqrt', '_test', '_test_generator',

'_urandom', '_warn', 'betavariate', 'choice', 'expovariate', 'gammavariate', 'gauss',

'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randint',

'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'triangular', 'uniform',

'vonmisesvariate', 'weibullvariate']

What are list methods?

Python list methods are a list of built-in functions that are used to modify the lists as per the convenience of the user. 

How do you list all functions in Python?

The python dir() can be used to list all the functions and attributes of a particular module or class.

Share with friends

Customize your course in 30 seconds

Which class are you in?
5th
6th
7th
8th
9th
10th
11th
12th
Get ready for all-new Live Classes!
Now learn Live with India's best teachers. Join courses with the best schedule and enjoy fun and interactive classes.
tutor
tutor
Ashhar Firdausi
IIT Roorkee
Biology
tutor
tutor
Dr. Nazma Shaik
VTU
Chemistry
tutor
tutor
Gaurav Tiwari
APJAKTU
Physics
Get Started

Leave a Reply

Your email address will not be published. Required fields are marked *

Download the App

Watch lectures, practise questions and take tests on the go.

Customize your course in 30 seconds

No thanks.