Python Language List: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 16: Line 16:
<syntaxhighlight lang='py'>
<syntaxhighlight lang='py'>
l.append(e)
l.append(e)
</syntaxhighlight>
===Delete the Last Element===
<syntaxhighlight lang='py'>
del l[-1]
</syntaxhighlight>
Assign the sublist to <code>l</code>:
<syntaxhighlight lang='py'>
l = l[:-1]
</syntaxhighlight>
</syntaxhighlight>


==Delete All Elements==
==Delete All Elements==

Revision as of 02:49, 17 February 2022

Internal

Overview

A list is a mutable sequence type that contains zero or more elements and whose elements can be of different types.

Access to a List

Size of a List

The number of elements is given by the len() function:

l = [...]
print(len(l))

Modify a List

Modify Individual Elements

Append an Element

l.append(e)

Delete the Last Element

del l[-1]

Assign the sublist to l:

l = l[:-1]

Delete All Elements