List

List

Mutable, list can be modified

List needs to be in square bracket [], for example: [1,2,3,4,5] or [β€˜a’,’b’,’c’] or [1,2,3,’a’,’b’,’10’]

List is a sequence, iterable

l=[β€˜a’,’b’,’c’]

l[0]=β€œa”

l[1]=β€œb”

l[2]=β€œc”

It is zero based indexing, index starts from zero

List can be iterated through:

for i in l:
    print(i)

Convert to List, use function list()

For example:

n=12345

list(n) becomes [1,2,3,4,5]

List is an object, meaning it has methods and attributes that can be invoked

To see all methods, type

help(<list variable>)

In Jupyter notebook, to see list of methods or attributes

Press shift key after enter <list variable>.

Fibonacci series:

the sum of two elements defines the next

running it will display:

Last updated

Was this helpful?