Lists in Python are:
Lists — Important Questions
SUMMARY: This chapter introduces the concept of lists in Python, a fundamental data structure used to store collections of items.
KEY TOPICS: list creation, list indexing, list slicing, list methods, list operations, nested lists, list comprehension, mutable vs immutable types, iterating through lists, applications of lists
The output of len([1,2,3,4,5]) is:
Check answerHide answer
Which method adds an element to the end of a list?
Check answerHide answer
The output of [1,2,3] + [4,5,6] is:
Check answerHide answer
Which of the following removes the last element of a list?
Check answerHide answer
What will be the output of the expression my_list = [1, 2, 3]; my_list[1] = 4; my_list?
Check answerHide answer
Which of the following methods can be used to insert an element at a specific position in a list?
Check answerHide answer
What is the result of the following code: list1 = [1, 2, 3]; list2 = list1 * 2?
Check answerHide answer
Which of the following statements about list slicing is true?
Check answerHide answer
What will be the output of the following code: my_list = [1, 2, 3]; my_list.append([4, 5])?
Check answerHide answer
Which of the following operations will result in a TypeError?
Check answerHide answer
What does the method pop() do when called on a list without any arguments?
Check answerHide answer
Given the list my_list = [1, 2, 3, 4, 5], what will my_list[1:4] return?
Check answerHide answer
Which of the following is a characteristic of lists in Python?
Check answerHide answer
What will be the output of the following code: nested_list = [[1, 2], [3, 4]]; nested_list[0][1]?
Check answerHide answer
Differentiate between append() and extend() methods of a list.
Differentiate between remove() and pop() methods of a list.
Write Python code to find the maximum element in a list.
Explain list slicing with an example.
How can you sort a list in descending order in Python?
What is a nested list in Python? Provide an example.
View sample solutionHide solution
How do you access the third element of a list named 'my_list'?
View sample solutionHide solution
What is list comprehension in Python? Give an example.
View sample solutionHide solution
Explain the difference between mutable and immutable types in Python with respect to lists.
View sample solutionHide solution
How can you iterate through a list using a for loop? Provide a code snippet.
View sample solutionHide solution
Compare list and tuple in Python with the help of a table on five features.
Differentiate between append() and extend() methods of a list in tabular form.
Compare remove() and pop() list methods with the help of a table.
Write a Python program to find the second largest number in a list.
Discuss any five built-in list methods in Python with one example each.
Write a Python program to find the sum of all even numbers in a list using a for loop.
Assertion (A): Lists are mutable.
Reason (R): Their elements can be changed after the list is created.
Show explanationHide explanation
Assertion (A): Lists can store elements of different data types.
Reason (R): Python lists are heterogeneous.
Show explanationHide explanation
Assertion (A): len() can be used to find the size of a list.
Reason (R): It returns the count of elements in the list.
Show explanationHide explanation
Assertion (A): The append() method modifies the list in place.
Reason (R): It adds the argument as a single element at the end.
Show explanationHide explanation
Assertion (A): Sorting a list of strings is case-sensitive by default.
Reason (R): Capital letters come before lowercase in ASCII order.
Show explanationHide explanation
Assertion (A): A list in Python can be created using square brackets.
Reason (R): Lists can also be created using the list() constructor.
Show explanationHide explanation
Assertion (A): List indexing in Python starts from 1.
Reason (R): Python uses zero-based indexing for lists.
Show explanationHide explanation
Assertion (A): List slicing allows you to extract a portion of a list.
Reason (R): Slicing can only be performed on strings, not on lists.
Show explanationHide explanation
Statement 1: Lists in Python are ordered collections.
Statement 2: The position of an element is preserved.
Show answerHide answer
Statement 1: Lists support both positive and negative indexing.
Statement 2: Negative indices count from the end.
Show answerHide answer
Statement 1: Lists are created using square brackets.
Statement 2: An empty list is denoted by [].
Show answerHide answer
Statement 1: The 'in' operator checks element membership.
Statement 2: The 'not in' operator checks for absence.
Show answerHide answer
Statement 1: List comprehension is a concise way to create lists.
Statement 2: It uses a for clause inside square brackets.
Show answerHide answer
Statement 1: Lists in Python are immutable data structures.
Statement 2: You can change the elements of a list after it has been created.
Show answerHide answer
Statement 1: List slicing allows you to extract a portion of a list.
Statement 2: List slicing can only be done using positive indices.
Show answerHide answer
Statement 1: The append() method adds an element to the end of a list.
Statement 2: The insert() method can add an element at any specified index in a list.
Show answerHide answer
-
Which function returns the number of elements in the list?Alen(marks)Bsize(marks)Clength(marks)Dcount(marks)
-
Lists in Python are:AMutableBImmutableCSetDTuple
-
Write a Python program to compute average max min and list students above the average.
Show answersHide answers
Predict the output of each list operation.
| Operation on a = [1, 2, 3] | Result |
|---|---|
| a.append(4) | ? |
| a.extend([5, 6]) | ? |
| a.insert(0, 0) | ? |
| a.remove(3) | ? |
| a.pop() | ? |
| a.sort(reverse=True) | ? |
Study the table of list operations and answer:
| Operation | Use | Example | Result |
|---|---|---|---|
| append() | Add at end | [1,2].append(3) | [1,2,3] |
| extend() | Add multiple | [1,2].extend([3,4]) | [1,2,3,4] |
| insert() | Add at position | [1,3].insert(1,2) | [1,2,3] |
| remove() | Remove value | [1,2,3].remove(2) | [1,3] |
| pop() | Remove last | [1,2,3].pop() | [1,2] |
-
Which method adds a single element at the end of the list?Aappend()Bextend()Cadd()Dinsert()
-
Which method adds multiple elements to a list?Aappend()Bextend()Cinsert()Djoin()
-
Discuss any five list methods in Python with examples.
Show answersHide answers
Study the list memory layout and operations and answer:
-
Which method adds a single element at the end of a list?Aappend()Bextend()Cinsert()Dpop()
-
For lst = [10, 20, 99, 40, 50] what is lst[1:4]?A[10, 20]B[20, 99, 40]C[20, 30, 40]D[10, 20, 99, 40, 50]
-
Discuss any five list operations in Python with examples.
Show answersHide answers
Make a full Computer Science paper on Lists.
Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.
Generate your paper — free