Operations on Lists
Functions That Python Provides, and Operations on Strings, introduced a few of Python’s built-in functions. Some of these, such as len, can be applied to lists, as well as others we haven’t seen before. (See the following table.)
|
Function |
Description |
|---|---|
|
len(L) |
Returns the number of items in list L |
|
max(L) |
Returns the maximum value in list L |
|
min(L) |
Returns the minimum value in list L |
|
sum(L) |
Returns the sum of the values in list L |
|
sorted(L) |
Returns a copy of list L where the items are in order from smallest to largest (This does not mutate L.) |
Here are some examples. The half-life of a radioactive substance is the time taken for half of it to decay. After twice this ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access