A list is a collection of values. Remember, it may contain different types of values.
To define a list, you must put values separated with commas in square brackets. You don’t need to declare a type for a list either.
A. Slicing a List
You can slice a list the way you’d slice a string- with the slicing operator.
Indexing for a list begins with 0, like for a string. A Python doesn’t have arrays.
B. Length of a List
Python supports an inbuilt function to calculate the length of a list.
C. Reassigning Elements of a List
A list is mutable. This means that you can reassign elements later on.
D. Iterating on the List
To iterate over the list we can use the for loop. By iterating, we can access each element one by one which is very helpful when we need to perform some operations on each element of list.
E. Multidimensional Lists
A list may have more than one dimension. Have a detailed look on this in DataFlair’s tutorial on Python Lists.
No comments:
Post a Comment