PYTHON LISTS:
LIST DECLARATION:
CHARACTERISTICS OF PYTHON:
- Ordered: Lists maintain the order of elements as they are added, allowing predictable access by index.
- Mutable: Lists can be changed after creation, enabling the addition, modification, or removal of elements.
- Heterogeneous Elements: Lists can hold diverse data types, accommodating numbers, strings, booleans, and more within a single list.
- Variable Length: Lists can dynamically grow or shrink in size, accommodating varying numbers of elements.
- Indexing and Slicing: Elements in a list are accessed by index, with the option to extract sublists using slicing.
- Iterability: Lists are iterable, allowing you to loop through their elements using iteration constructs like for loops.
INDEXING AND SLICING:
- Indexing allows you to access individual elements of a list using their position (index).
- The index starts from 0 for the first element, and it increments by 1 for each subsequent element.
- You can also use negative indices to count from the end of the list.
2. Slicing:
- Slicing allows you to extract a portion (sublist) from a list.
- The syntax for slicing is a list[start: end], where the start is inclusive and the end is exclusive.
- If you omit start, slicing starts from the beginning; if you omit end, slicing goes to the end of the list.
EXAMPLE:
UPDATING LIST VALUES:
EXAMPLE:
BUILT-IN FUNCTION:
Sr.No. |
Function with Description |
1 |
Compares elements of both
lists. |
2 |
Gives the total length of the
list. |
3 |
Returns item from the list
with max value. |
4 |
Returns item from the list
with min value. |
5 |
Converts a tuple into list. |
HERE ARE SOME OTHER ADDITIONAL METHOD:
Sr.No. |
Methods with Description |
1 |
Appends object obj to list |
2 |
Returns count of how many
times obj occurs in list |
3 |
Appends the contents of seq to
list |
4 |
Returns the lowest index in
list that obj appears |
5 |
Inserts object obj into list
at offset index |
6 |
Removes and returns last
object or obj from list |
7 |
Removes object obj from list |
8 |
Reverses objects of list in
place |
9 |
Sorts objects of list, use
compare func if given |
0 Comments