DEV Community 👩‍💻👨‍💻

Cover image for Python Lists
EzeanaMichael
EzeanaMichael

Posted on

Python Lists

Lists are a collection of data or the same or different data types that can be stored in a systematic part of the memory.
A way of creating an empty list in Python is by equating an identifier to square brackets
I.e
Numbers= []
To create a list
Code
Image description
Output

Image description
Code
Image description
Output
Image description

On other instances or occasions, you can create a list with multiple datatypes.
Code
Image description
Output
Image description

Items in the list can be accessed
This is done my specifying the nth item on the list, list numeration starts from zero
So you use print(list[0]) to print the first item on the list then print(list[1]) for the second item.

Code
Image description
Output
Image description
Along with that, you can also reassign different values in place.

Code
Image description
Output
Image description
Now that we know how to create a list we can also alter the list by using some special keywords

List.append(5)-the word append is to add more values to a list.
List.remove(2)- deletes the number 2 in the list.
Max(list)-in a list of integers finds the maximum number.
Min(list)-in a list of integers find the minimum number.
List.reverse()-reverses the list
List.sort-sorts the list.
Code
Image description
Output
Image description
Lists are very useful in programming as we will see in later lessons.
Thanks for reading, like, share, comment.

Oldest comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.