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:
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?