Hey guys! Today I’m going to talk about list in Python.

Like a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in a list are called elements or sometimes items. There are several ways to create a new list; the simplest is to enclose the elements in square brackets ([something]):

numbers = [10, 20, 30, 40]

stuffs = [‘banana’, ‘candle’, ‘brownie’, ‘string’]

For creating a list you need to establish the name of the list and then assign the value of the list.

Next, for print a value of the list you need to type the command print() and between the parenthesis you type the name of the list followed by the number of the element desired. All the elements on a list are numbered from 0.

If you want to know the number of the values inside the list you need to type the command len().

xs

 

CC BY 4.0 #Mastery23 by jsphsalazar is licensed under a Creative Commons Attribution 4.0 International License.