The sequence is the most fundamental data structure in Python. Every component in a series has an index, or location, assigned to it. Zero is the first index, one is the second, and so on. Although there are six built-in sequence types in Python, the most used ones are lists and tuples, which are what we’ll be working on in this article. All sequence kinds allow you to do specific tasks. Indexing, slicing, adding, multiplying, and membership checking are some of these operations. Furthermore, Python includes built-in functions for determining a sequence’s length as well as its greatest and smallest members.
Python Lists: A list of comma-separated values objects enclosed in square brackets is the most flexible datatype that Python has to offer. One important feature of a list is that its entries don’t have to be of the same kind. It’s easy to create a list by simply placing several values, separated by commas, between square brackets.
list1=[‘New York’, ‘New Delhi’, ‘Sydney’, ‘Totonto’, ‘Sania’]
list2=[20, 30, 34, 45, 55, 38]
How to Access Values in Lists: To retrieve values from lists, use the square brackets for slicing in conjunction with the index or indices to extract the value present at that index.
print(“list1[2]: “, list1[2])
print(“list2[2:4]: “, list2[2:4])
The output will be:
list1[2]: Sydney
list2[2:4]: [34,45]