FREE INTERACTIVE ONLINE COURSE

Python 3

FOR BEGINNERS


"The first Python course that simply amazed me. Very well explained and easy to understand." (Alexandru Cosmin)

"The best Python course in Romania." (Iulian Geană)


ALL REVIEWS
LESSON 10
PAGE 2 / 5
Lists
Home >>> Free Online Lessons, Python 3

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:
Editor - lesson_10.py
       
Console/Output done
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.
 home   list  CONTENTS   perm_identity   arrow_upward