See More

0<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307453,\"answer\":\"

1<\/span><\/p>\",\"correct\":true,\"sort_order\":1},{\"id\":307454,\"answer\":\"

5<\/span><\/p>\",\"correct\":false,\"sort_order\":2},{\"id\":307455,\"answer\":\"

Error<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

Unlike Python\u2019s built-in list, the <\/span>array module<\/strong><\/b> is for <\/span>homogeneous arrays <\/strong><\/b>(all elements must be of the same type) hence <\/span>'i' <\/strong><\/b>denotes \\\"unsigned integers\\\" and then accessing the first element of the array returns the value 1.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-06-13 - 12:48:21\"},{\"id\":77206,\"title\":\"Python Arrays-question-3\",\"slug\":\"which-of-the-following-methods-is-used-to-add-1\",\"question\":\"

Which of the following methods is used to add an element to the end of an array?<\/span><\/p>\",\"answers\":[{\"id\":307456,\"answer\":\"

insert()<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307457,\"answer\":\"

append()<\/span><\/p>\",\"correct\":true,\"sort_order\":1},{\"id\":307458,\"answer\":\"

extend()<\/span><\/p>\",\"correct\":false,\"sort_order\":2},{\"id\":307459,\"answer\":\"

add()<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

The append method adds an element to the end of the array.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-03-10 - 12:43:36\"},{\"id\":77207,\"title\":\"Python Arrays-question-4\",\"slug\":\"what-will-be-the-output-of-the-following-codepythonfrom\",\"question\":\"

What will be the output of the following code?<\/span><\/p>\\n Python<\/gfg-tab>\\n \\n

<\/span>from<\/span> array<\/span> import<\/span> array<\/span>\\narr<\/span> =<\/span> array<\/span>(<\/span>'i'<\/span>,<\/span> [<\/span>1<\/span>,<\/span> 2<\/span>,<\/span> 3<\/span>])<\/span>\\narr<\/span>.<\/span>insert<\/span>(<\/span>1<\/span>,<\/span> 4<\/span>)<\/span>\\nprint<\/span>(<\/span>arr<\/span>)<\/span>\\n<\/pre><\/div><\/code>\\n        <\/gfg-panel>\\n    <\/gfg-tabs>


<\/p>\",\"answers\":[{\"id\":307460,\"answer\":\"

array('i', [1, 4, 2, 3])<\/span><\/p>\",\"correct\":true,\"sort_order\":0},{\"id\":307461,\"answer\":\"

array('i', [4, 1, 2, 3])<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307462,\"answer\":\"

array('i', [1, 2, 3, 4])<\/span><\/p>\",\"correct\":false,\"sort_order\":2},{\"id\":307463,\"answer\":\"

Error<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"


<\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-01-13 - 17:03:34\"},{\"id\":77208,\"title\":\"Python Arrays-question-5\",\"slug\":\"what-does-the-index-method-do-in-an-array\",\"question\":\"

What does the index method do in an array?<\/span><\/p>\",\"answers\":[{\"id\":307464,\"answer\":\"

Returns the last occurrence of a specified value<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307465,\"answer\":\"

Inserts a value at a specified position<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307466,\"answer\":\"

Returns the index of the first occurrence of a specified value<\/span><\/p>\",\"correct\":true,\"sort_order\":2},{\"id\":307467,\"answer\":\"

Removes an element at a specified position<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

The index method returns the index of the first occurrence of a specified value.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-03-10 - 12:52:22\"},{\"id\":77209,\"title\":\"Python Arrays-question-6\",\"slug\":\"how-to-create-an-empty-array-of-integers-in\",\"question\":\"

How to create an empty array of integers in Python using the array module?<\/span><\/p>\",\"answers\":[{\"id\":307468,\"answer\":\"

arr = array.array('i')<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307469,\"answer\":\"

arr = array.array('i', [])<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307470,\"answer\":\"

Both a and b<\/span><\/p>\",\"correct\":true,\"sort_order\":2},{\"id\":307471,\"answer\":\"

None of the above<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

Both array('i') and array('i', []) can be used to create an empty array of integers.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-08-02 - 17:01:34\"},{\"id\":77210,\"title\":\"Python Arrays-question-7\",\"slug\":\"what-does-the-following-code-printpythonfrom-array-import-array\",\"question\":\"

What does the following code print?<\/span><\/p>\\n Python<\/gfg-tab>\\n \\n

<\/span>from<\/span> array<\/span> import<\/span> array<\/span>\\narr<\/span> =<\/span> array<\/span>(<\/span>'i'<\/span>,<\/span> [<\/span>1<\/span>,<\/span> 2<\/span>,<\/span> 3<\/span>])<\/span>\\narr<\/span>[<\/span>1<\/span>]<\/span> =<\/span> 5<\/span>\\nprint<\/span>(<\/span>arr<\/span>)<\/span>\\n<\/pre><\/div><\/code>\\n        <\/gfg-panel>\\n    <\/gfg-tabs>


<\/p>\",\"answers\":[{\"id\":307472,\"answer\":\"

array('i', [1, 2, 3])<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307473,\"answer\":\"

array('i', [5, 2, 3])<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307474,\"answer\":\"

array('i', [1, 5, 3])<\/span><\/p>\",\"correct\":true,\"sort_order\":2},{\"id\":307475,\"answer\":\"

Error<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

Assigning a new value to an element at a specific index updates the array.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-01-13 - 17:03:34\"},{\"id\":77211,\"title\":\"Python Arrays-question-8\",\"slug\":\"what-is-the-result-of-the-following-codepythonfrom-array\",\"question\":\"

What is the result of the following code?<\/span><\/p>\\n Python<\/gfg-tab>\\n \\n

<\/span>from<\/span> array<\/span> import<\/span> array<\/span>\\narr1<\/span> =<\/span> array<\/span>(<\/span>'i'<\/span>,<\/span> [<\/span>1<\/span>,<\/span> 2<\/span>,<\/span> 3<\/span>])<\/span>\\narr2<\/span> =<\/span> array<\/span>(<\/span>'i'<\/span>,<\/span> [<\/span>4<\/span>,<\/span> 5<\/span>])<\/span>\\narr1<\/span> +=<\/span> arr2<\/span>\\nprint<\/span>(<\/span>arr1<\/span>)<\/span>\\n<\/pre><\/div><\/code>\\n        <\/gfg-panel>\\n    <\/gfg-tabs>


<\/p>\",\"answers\":[{\"id\":307476,\"answer\":\"

array('i', [1, 2, 3, 4, 5])<\/span><\/p>\",\"correct\":true,\"sort_order\":0},{\"id\":307477,\"answer\":\"

array('i', [4, 5, 1, 2, 3])<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307478,\"answer\":\"

array('i', [1, 2, 3, 9, 10])<\/span><\/p>\",\"correct\":false,\"sort_order\":2},{\"id\":307479,\"answer\":\"

Error<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

The += operator concatenates two arrays of the same type.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-03-10 - 12:54:26\"},{\"id\":77212,\"title\":\"Python Arrays-question-9\",\"slug\":\"what-is-the-time-complexity-of-accessing-an-element-6\",\"question\":\"

What is the time complexity of accessing an element in an array by index?<\/span><\/p>\",\"answers\":[{\"id\":307480,\"answer\":\"

O(n)<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307481,\"answer\":\"

O(log n)<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307482,\"answer\":\"

O(1)<\/span><\/p>\",\"correct\":true,\"sort_order\":2},{\"id\":307483,\"answer\":\"

O(n^2)<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

Accessing an element by index in an array takes constant time, O(1).<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-01-13 - 17:03:34\"},{\"id\":77213,\"title\":\"Python Arrays-question-10\",\"slug\":\"which-of-the-following-operations-is-not-allowed-on\",\"question\":\"

Which of the following operations is not allowed on a Python array?<\/span><\/p>\",\"answers\":[{\"id\":307484,\"answer\":\"

Accessing an element by index<\/span><\/p>\",\"correct\":false,\"sort_order\":0},{\"id\":307485,\"answer\":\"

Slicing<\/span><\/p>\",\"correct\":false,\"sort_order\":1},{\"id\":307486,\"answer\":\"

Adding elements of different types<\/span><\/p>\",\"correct\":true,\"sort_order\":2},{\"id\":307487,\"answer\":\"

Iterating through elements<\/span><\/p>\",\"correct\":false,\"sort_order\":3}],\"explanation\":\"

Python arrays created using the array module can only store elements of the same type.<\/span><\/p>\",\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2025-01-13 - 17:03:34\"}],\"quiz\":{\"id\":4555,\"top_description\":\"


<\/p>\",\"question_count\":10,\"bottom_description\":\"


<\/p>\",\"title\":\"Python Arrays\",\"slug\":\"python-arrays\",\"category\":[{\"id\":4,\"name\":\"Misc\",\"slug\":\"misc\",\"origin_term_id\":4,\"origin_slug\":\"misc\"},{\"id\":1842,\"name\":\"Python\",\"slug\":\"python\",\"origin_term_id\":1789,\"origin_slug\":\"programming-language\/python\"}],\"show_answer\":3,\"created_on\":\"2024-12-20 - 16:32:18\",\"updated_on\":\"2024-12-20 - 16:53:44\"}}"); Python Arrays - GeeksforGeeks