How to Use List del Method in PythonPython Basics


The del list() method deletes the (num+1)th element.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

list = ['MIT', 'Stanford','NWU', 2012, 2019]

print("list is:  ", list)
del list[2]
print("Delete the third element : ", list)

Output:

list is:   ['MIT', 'Stanford', 'NWU', 2012, 2019]
Delete the third element :  ['MIT', 'Stanford', 2012, 2019]

Syntax

del list[num]

Parameters

The method doesn’t take any parameters.

Return Value

It doesn’t return any values.

© 2024 Learnwithgpt.org, all rights reserved. Privacy Policy | Contact Us