Write 6 functions for list and give the example to explain the same
Answers
Answer:
list is an ordered set of values, where each value is identified by an index. The values that make up a list are called its elements. Lists are similar to strings, which are ordered sets of characters, except that the elements of a list can have any type. Lists and strings — and other things that behave like ordered sets — are called sequences.
9.1. List values
There are several ways to create a new list; the simplest is to enclose the elements in square brackets ( [ and ]):
[10, 20, 30, 40]
["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 (mirabile dictu) another list:
["hello", 2.0, 5, [10, 20]]
A list within another list is said to be nested.
Finally, there is a special list that contains no elements. It is called the empty list, and is denoted [].
Like numeric 0 values and the empty string, the empty list is false in a boolean expression:
>>> if []:
... print 'This is true.'
... else:
... print 'This is false.'
...
This is false.
>>>
Functions can be stored as elements of a list or any other data structure in Python. For example, if we wish to perform multiple operations to a particular number, we define apply_func(L, x) that takes a list of functions, L and an operand, x and applies each function in L on x.