Computer Science - Informatics Practices Class XI/XII Python List Solved Test Part 7

 

Computer Science - Informatics Practices Class XI/XII Python List Solved Test  Part 7

Q1. Write the role of reverse() function in list.

Q2. reverse() function create new list. (T/F)

Q3. >>> a = [1,2,3,4]

    >>> a.reverse()

    >>> print(a)

Write the output of above code.

Q4. What type of error return by index() function,

    if element is not present in list?

Q5. a = [1,5,7,5]

    b = a.index(5)

    print(b)

Write the output of above code.

Q6. Write the output of the following:

Code

Output

 

 

 

 

Q7. len() function returns the ______ of the list.

Q8. By default sort() function arrange the 

    elements in ________ order  

    (increasing/decreasing)

Q9. Write code to arrange elements of following 

    list in increasing order.

    A = [23,12,45,32,67,33]

Q10. What do you mean by nested list. Give one

     example of nested list.


  

SOLUTIONS

Q1. Write the role of reverse() function in list.

Ans reverse() function arrange the elements of 

    list in the reverse order.

Q2. reverse() function create new list. (T/F)

Ans. False

Q3. >>> a = [1,2,3,4]

    >>> a.reverse()

    >>> print(a)

Write the output of above code.

Ans. [4,3,2,1]

Q4. What type of error return by index() function,

    if element is not present in list?

Ans. Index error

Q5. a = [1,5,7,5]

    b = a.index(5)

    print(b)

Write the output of above code.

Ans. 1

Q6. Write the output of the following:

Code

Output

 Indexerror

 [1,'a',3,4]

 [4,5,6,7]

 

Q7. len() function returns the ______ of the list.

Ans length

Q8. By default sort() function arrange the 

    elements in ________ order  

    (increasing/decreasing)

Ans. increasing

Q9. Write code to arrange elements of following 

    list in increasing order.

    A = [23,12,45,32,67,33]

Ans. A.sort()

Q10. What do you mean by nested list. Give one

     example of nested list.

Ans. A list inside another list is called nested list. for example

A = [1,2,3,['a','b']]

 

 

 

 

No comments:

Post a Comment

Most Recently Published

File Handling Test 6

 File Handling Test 6 Q1 . Do we need to use the close() function when we use 'with' statement to open a file? Q2. Which mode you wi...

CS - IP Assignment/Worksheet