Data Types Can Vary!
Below we have created a new list, named
list_1, which contains as elements
three
strings, two
integers, and finally, a
float:
DETAILS
We created a list named
list_1 and displayed it.
We printed the first 3 elements using the "
:" operator, i.e.,
list_1[0],
list_1[1], and
list_1[2].
Remember that the last index (
3) is not included...
Then, we displayed the elements from index
3 to the right, i.e.,
list_1[3],
list_1[4], and
list_1[5]
(we did not specify the end index, so all were printed).
Negative Index. The last element of the list has the index
-1, the second to last has
-2, and so on. Above, we
displayed the list from right to left, similar to strings.
Operators "+", "*", in, and not in
We can
concatenate lists or
multiply one just like with strings, using the first two operators. Look at the example below:
Try to check if the string "
a" is in
list_1,
list_2, or
list_3 using commands like
"a" in list_1 or
"a" not in list_3!
Run the program, then proceed to the next page.