Lists
It is used to store Collection of data.
Lists are created using square brackets:
List Items Order cannot be changed.
It can have duplicate values.
Example
A list can contain different data types:
lists are defined as objects with the data type 'list':
The list() Constructor
Using the
list()
constructor to make a List:Access List Items
You can access them by referring to the index number. The index number starts with 0
Negative Indexing
-1 refers to the last item, -2 refers to the second last item etc.
Range of Indexes
You can specify a range of indexes by specifying where to start and where to end the range.
Return the third, fourth, and fifth item:
We can also ignore the list , by ignoring with the :Index
Example
thislist = ["a", "b", "c",1,2,True,"a","d","c"]
print(thislist)
print(thislist[:3])
#This will return the items from index 0 to index 3
thislist = ["a", "b", "c",1,2,True,"a","d","c"]
print(thislist)
print(thislist[3:])
#This will return the items from index 3 to index end
No comments:
Post a Comment
Thank you for visiting my blog