Q.Fill in the blank : ___________ is not a valid built-in function for list manipulations.
🔒You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
🔒 Start your 14-day free trial to unlock the full solution →Concept understanding — Python List Slicing, Methods and Manipulation
A list is a mutable ordered collection in Python that supports indexing, slicing and in-place modification of its elements. Methods such as append(), insert(), extend(), remove(), pop(), sort() and reverse() add, remove or reorder items, while built-in functions like len(), sum(), min() and max() aggregate list contents. Slicing with list[a:b:c] returns a new sublist, and traversal with a loop allows counting or transform …
Concept: Built-in methods of Python list objects
Python lists have specific methods attached to them for manipulation. We need to identify which option is not a valid list method.
Step 1: Check count() — this is a valid list method that returns the number of occurrences of a value: [1, 2, 2].count(2) gives 2.
Step 2: Check length() — Python does not have a length() method for lists. To find the length, we use the built-in function len(list), not list.length(). …
Python lists have methods like count(), append(), and extend(), but not length() — to find a list's length you use the built-in function len(), not a method called length(). The answer is (b).
Python lists come with a suite of built-in methods that let you manipulate them directly. The key is knowing which operations are methods (called on the list itself, like my_list.append(x)) versus which are standalone functions (like len(my_list)).
Let's examine each option:
-
count()— This is a valid list method. It returns the number of times a specified element appears in the list. For example,[1, 2, 2, 3].count(2)returns2. -
length()— This does not exist as a list method in Python. Many students coming from other languages (like JavaScript'sarray.lengthproperty) expect this, but Python uses the built-in functionlen(my_list)instead. There is nomy_list.length()method. -
append()— A fundamental list method that adds a single element to the end of the list.my_list.append(5)modifies the list in place. …
- CBSE 2026Set 91/41 markMCQQ.If L is a list with 6 elements, then which of the following statements will raise an exception ? (A) L.pop(1) (B) L.pop(6) (C) L.insert(1,6) (D) L.insert(6,1)
›Reveal solutionSolution
Python lists are 0-indexed. For a list of length 6, valid indices for
pop()are 0 to 5, soL.pop(6)raises anIndexError.insert()is more forgiving — an index at or beyond the end just appends. The answer is (B) L.pop(6).Python lists are 0-indexed, and the key is how different list methods treat an index at the boundary.
For a list
Lwith 6 elements, the valid indices for accessing or removing an existing element are 0, 1, 2, 3, 4, 5. Any attempt to remove an element at an index outside this range raises anIndexError.The
insert()method behaves differently: it says where to place a new element. If the index equals the list length, the element is appended; if the index is even larger, it is still appended. Soinsert()is more forgiving thanpop().Take a sample list
L = [10, 20, 30, 40, 50, 60]wherelen(L)is 6.-
(A)
L.pop(1)— index 1 exists, so this removes20. No exception. -
(B)
L.pop(6)—pop()needs0 <= index < len(L). Herelen(L)is 6, so the valid indices are 0 to 5. Index 6 is out of range, so this raises anIndexError.Watch outA common mistake is confusing the length of the list with the highest valid index. For a list of length N, the highest valid index is N minus 1, not N. …
-
- CBSE 2025Set 91/41 markQ.State True or False: "A Python List must always contain all its elements of same data type."
›Reveal solutionSolution
The statement is False. Python lists are heterogeneous containers — they can hold elements of different data types simultaneously, unlike arrays in some statically-typed languages.
The Concept: Dynamic Typing and Containers
The heart of this question lies in understanding how Python handles data types. Python is a dynamically typed language. This means variables don't have fixed types; instead, the type is attached to the value at runtime. A list is just a sequence of references to objects, and those objects can be anything — integers, strings, floats, other lists, functions, or even
None.In contrast, languages like C or Java require arrays (or typed lists like
ArrayList<Integer>) to hold elements of a single, predetermined type. Python deliberately avoids this restriction to be flexible.Watch outA common confusion arises from the word "list" itself. In everyday language, a list might imply a uniform collection (like a shopping list of only items). But in Python, a list is a general-purpose ordered container — uniformity is never required.
Step-by-Step Reasoning
-
Check the definition of a Python list.
The official Python documentation defines a list as a mutable, ordered sequence of items. It does not impose any type constraint on those items. The syntax
[1, "hello", 3.14]is perfectly valid. -
Test with a concrete example.
Run the following in any Python interpreter:
my_list = [42, "apple", 3.14, True, [1, 2]] print(my_list)This prints
[42, 'apple', 3.14, True, [1, 2]]without error. The list contains an integer, a string, a float, a boolean, and a nested list — five different types. -
Consider the underlying mechanism.
Each element in a Python list is a pointer (reference) to an object. The list itself only stores these references. Since Python objects carry their own type information, the list doesn't need to enforce a single type. This is fundamentally different from a C array, where memory is laid out contiguously for one type.
-
Address the "must always" phrasing. …
-
- CBSE 2025Set 91/41 markMCQQ.Consider the statements given below and then choose the correct output from the given options:
(A) ['CIT', 'CAT'] (B) ['TIC', 'TAC'] (C) ['CAT', 'CIT'] (D) ['TAC', 'TIC']L=['TIC', 'TAC'] print(L[::-1])›Reveal solutionSolution
The slice
[::-1]reverses the order of elements in the list, not the characters within each string, so['TIC', 'TAC']becomes['TAC', 'TIC'].When you work with lists in Python, slicing notation gives you powerful control over which elements you extract and in what order. The general form
[start:stop:step]lets you specify where to begin, where to end, and how to move through the list. The step parameter is the key here.A step of
-1tells Python to walk backward through the list. SoL[::-1]means "start at the end, go to the beginning, taking steps of -1"—in other words, reverse the entire list. Crucially, this operation reverses the sequence of elements, not the contents of individual elements.In the given code,
Lis a list containing two strings:'TIC'and'TAC'. When you apply[::-1], Python flips the order of these two items. The first element'TIC'moves to the second position, and the second element'TAC'moves to the first position. The strings themselves remain unchanged—'TIC'is still'TIC', not'CIT'. … - CBSE 2024Set 91/41 markMCQQ.Select the correct output of the following code: event="G20 Presidency@2023" L=event.split(' ') print(L[::-2]) (A) 'G20' (B) ['Presidency@2023'] (C) ['G20'] (D) 'Presidency@2023'
›Reveal solutionSolution
The code first splits the string into a list of words, then uses reverse slicing with a step of -2 to select elements from the end of the list, moving backwards and skipping every other element.
Let's break down this Python code step by step to understand its output. The core concepts here are string splitting and list slicing, both fundamental operations in Python.
First, we have the string
event = "G20 Presidency@2023". This string contains two distinct parts separated by a space.The next line,
L = event.split(' '), uses thesplit()method. This method is called on a string and, when given an argument like' '(a space), it divides the string into a list of substrings wherever that delimiter (the space) is found.In our case,
event.split(' ')will take "G20 Presidency@2023" and split it at the space between "G20" and "Presidency@2023".This operation results in a list:
['G20', 'Presidency@2023']. So, the variableLnow holds this list.NoteIf no delimiter is provided to
split(), it defaults to splitting by any whitespace (spaces, tabs, newlines) and also handles multiple consecutive whitespaces as a single delimiter, removing empty strings from the result. However, here we explicitly provided a single space' '.Finally, we have
print(L[::-2]). This is a list slicing operation. List slicing in Python uses the syntax[start:stop:step].start: The index where the slice begins (inclusive). If omitted, it defaults to the beginning of the list.stop: The index where the slice ends (exclusive). If omitted, it defaults to the end of the list.step: The increment between elements. If omitted, it defaults to1.
In
[::-2]:- Both
startandstopare omitted. - The
stepis-2. A negative step value indicates that the slicing should proceed in reverse order, starting from the end of the list.
Let's apply this to our list
L = ['G20', 'Presidency@2023']:- Since the step is negative, Python starts from the last element of the list. The last element of
Lis'Presidency@2023'. This element is included in the result. - From this position, it moves backwards by 2 steps.
- The index of
'Presidency@2023'is1(or-1when counting from the end). - Moving back 2 steps from index
1would take us to index1 - 2 = -1. This is the same element. …
- The index of
- CBSE 2023Set 91/11 markMCQQ.Which function returns the sum of all elements of a list?(a) count()(b) sum()(c) total()(d) add()
›Reveal solutionSolution
Python provides a built-in
sum()function that computes the sum of all numeric elements in an iterable. The answer is (b).Python's standard library includes several aggregate functions that operate on collections. When you need to add up all numbers in a list, you want a function that iterates through every element and maintains a running total.
The
sum()function does exactly this. It takes an iterable (like a list, tuple, or range) and returns the arithmetic sum of its elements. The syntax is straightforward:sum(iterable, start=0)where
startis an optional initial value (defaults to 0) that gets added to the sum.Let me show why each option is or isn't correct:
-
count()is a list method that counts occurrences of a specific value. For example,[1, 2, 2, 3].count(2)returns2. It doesn't sum anything. -
sum()is the built-in function we need.sum([1, 2, 3, 4])returns10. It works with any numeric iterable and is part of Python's core built-ins. -
total()doesn't exist as a built-in Python function. You'd get aNameErrorif you tried to call it without defining it first. …
-
- CBSE 2023Set 91/41 markMCQQ.Fill in the blank : ___________ is not a valid built-in function for list manipulations.(a) count()(b) length()(c) append()(d) extend()
›Reveal solutionSolution
Python lists have methods like
count(),append(), andextend(), but notlength()— to find a list's length you use the built-in functionlen(), not a method calledlength(). The answer is (b).Python lists come with a suite of built-in methods that let you manipulate them directly. The key is knowing which operations are methods (called on the list itself, like
my_list.append(x)) versus which are standalone functions (likelen(my_list)).Let's examine each option:
-
count()— This is a valid list method. It returns the number of times a specified element appears in the list. For example,[1, 2, 2, 3].count(2)returns2. -
length()— This does not exist as a list method in Python. Many students coming from other languages (like JavaScript'sarray.lengthproperty) expect this, but Python uses the built-in functionlen(my_list)instead. There is nomy_list.length()method. -
append()— A fundamental list method that adds a single element to the end of the list.my_list.append(5)modifies the list in place. …
-
🎓Unlock everything free for 14 days
- ✓Full step-by-step solutions
- ✓Concept-first explanations
- ✓Methods, shortcuts & mistakes
- ✓PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.