A list is a
sequence of values that are nested into one function. These elements can be
strings, number, and even lists. You can have many types of elements within the
same list, for example:
Colors = [ ‘red’,
‘blue’, ’yellow’ ]
Numbers = [
1, 2, 3 ]
List = [ 4,
[5, 6]]
Other = [ ‘red’,
2, [5, 6] ]
As you can
see, for creating a list you need to establish the name on the list followed by
an equal sign (which means ‘assignment’). After the equal sign you start naming
the elements included in the list. These elements are nested inside square
brackets [] and separated by commas. If the element being established is a
string, it needs to be between quotation marks.
For
printing the whole list you type the command print() and between the
parenthesis you type the name of the list. For printing just one element of the
list you type the command print() and between the parenthesis you type the name
of the list followed by the number of the element between square brackets.
NOTE: The
elements on a list are numbered starting from 0
For knowing
how many elements a list contains, you can use the command len(), between the
parenthesis you type the name of the list.
Also, you can change an element on a list by
typing the name of the list followed by position of the element you want to
change between square brackets. After that, you place the equal sign followed
by the element you want to replace it with.
No hay comentarios:
Publicar un comentario