Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




7.2 The del statement

There is a way to remove an item from a list given its index instead of its value: the del statement. This can also be used to remove slices from a list (which we did earlier by assignment of an empty list to the slice). For example:

    >>> a
    [-1, 1, 66.6, 333, 333, 1234.5]
    >>> del a[0]
    >>> a
    [1, 66.6, 333, 333, 1234.5]
    >>> del a[2:4]
    >>> a
    [1, 66.6, 1234.5]

del can also be used to delete entire variables:

    >>> del a

Referencing the name a hereafter is an error (at least until another value is assigned to it). We'll find other uses for del later.

  Published under the terms of the Python License Design by Interspire