Python Programming Quiz

Quiz on Lists in Python

Time left: 300 seconds

Q.1. List can contain data of only one data type

Select Your Option

A list can store mixed data types.

Q.2. What is the output of following program?
          
            list1 = ['pear', 'mango', 'apple', 'pomegranate']
            print(max(list1))
          
          

Select Your Option

max checks the first character of all the strings and finds the highest (in ASCII order) and returns that as output. If more than 1 string has the same first character, Python checks the following letters of each element and compares them. Here, 'po' has higher ascii value tha 'pe'. Hence the output is 'pomegranate'.

Q.3. What is the output of following program?
          
            L = [70, 20, 90, 10, 50]
            L.sort()
            print(L)
          
          

Select Your Option

The sort() method sorts the list ascending by default.

Q.4. Which statement of the following is false?

Select Your Option

2 lists cannot be directly subtracted in Python. However, modules such as numpy and zip or looping statements can be used to subtract two lists.

Q.5. What is the output of following program?
          
            l = [1,2,3,4,5,6,7,8,9]
            print(5 in l)
          
          

Select Your Option

The print statement checks for value 5 in list l. Since, it is present in the list, True will be printed on the console.

Q.6. Which of the following is the correct syntax to get "[5,4,3,2,1]" as output for list:
l = [1,2,3,4,5,6,7,8,9]

Select Your Option

The values till index 4 will be printed with a step of -1 (ie, in reverse order).

Q.7. Initializing a list as follows would give an error:
list1 = ["abc", 34, True, 40, "male"]

Select Your Option

A list can store mixed data types.

Q.8. Given: l = [[1,2,3],[4,5,6],[7,8,9]]
Which of the following will give the output as 6

Select Your Option

6 is present at l[1][2] index

Q.9. print(l[8]) in l = [7,9,6,2,8,3,5,1] would give

Select Your Option

Indexing in Python is a way to refer the individual items within an iterable by its position. The position count starts in Python at 0. Hence, a list of length 8 will have indices from 0 to 7. Referring to index 8 will therefore give an error as it is out of range of the list indices.

Q.10. What would be the output of following program?
          
            l = [65,3,6,75,4,36,67,56,54]
            l.pop(2)
            l.pop()
            l.pop(0)
            print(l)
          
          

Select Your Option

The pop() method removes the item at the given index from the list and returns the removed item. The argument passed to the method is optional. If not passed, the default index -1 is passed as an argument (index of the last item).

Q.11. Determine Output of the following snippet of code:
          
            list = ["Hello", "Python","and","Java"]
            print(list[0][0]+list[1][1]+list[2][2]+list[3][3])
          
          

Select Your Option

list[0][0]=H ; list[1][1]=y ; list[2][2]=d ; list[3][3]=a

Q.12. Whats the total number of elements, max number of rows and columns in the 2-dimentional list given below:
l = [[1],[2,3],[7,8,9],[3],[9,4,5,1],[9,8]]

Select Your Option

There are 6 rows, 4 max columns and total 13 elements

Q.13. What would be contents of the list if following code is executed?
          
            l = list(range(1,20,3))
          
          

Select Your Option

Numbers between 1 to 20 with a step of 3 will be added to the list. Hence, the list will contain elements [1,4,7,10,13,16,19]

Q.14. Contents of list after following code is executed
          
            l = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
            l[7] = 15
          
          

Select Your Option

The second statement will re-write the 7th index element (ie 14) as 15

Q.15. What will be the output of following code:
          
            l = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
            print(sorted(l,reverse=True))
          
          

Select Your Option

The sorted function will reverse sort the list and then print it.

Instructions:-

  1. This Quiz is based on Lists in Python
  2. Each correct answer will carry 2 points
  3. Once an option is selected you cannot select any other, So choose wisely
  4. Do not refresh the page as it will reset the quiz
  5. Once the time is up the quiz will automatically get submitted with no of Question responded
  6. Your total score alongwith your name will be shown after submission of the Quiz
  7. Wish you ALL THE BEST 👍👍

START

Results:-

Hi




Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post