While searching for a certain element in a list, avinash used the index values of each
element. Justify his method of accessing elements in a list
Answers
Answer:
A list is an ordered collection of values. The values that make up a list are called its elements, or its items. We will use the term element or item to mean the same thing. Lists are similar to strings, which are ordered collections of characters, except that the elements of a list can be of any type. Lists and strings — and other collections that maintain the order of their items — are called sequences.
11.1. List values
There are several ways to create a new list; the simplest is to enclose the elements in square brackets ([ and ]):
1
2
ps = [10, 20, 30, 40]
qs = ["spam", "bungee", "swallow"]
The first example is a list of four integers. The second is a list of three strings. The elements of a list don’t have to be the same type. The following list contains a string, a float, an integer, and (amazingly) another list:
1
zs = ["hello", 2.0, 5, [10, 20]]
A list within another list is said to be nested.
Finally, a list with no elements is called an empty list, and is denoted [].
We have already seen that we can assign list values to variables or pass lists as parameters to functions:
Explanation:
is this helpful