1. What is a Python array?
a) A built-in data type for storing key-value pairs
b) A linear data structure for storing elements of the same data type
c) A collection of unordered elements
d) A list of dictionaries
Answer:
b) A linear data structure for storing elements of the same data type
Explanation:
A Python array is a linear data structure for storing elements of the same data type.
2. How are elements accessed in a Python array?
a) Using a key
b) Using an index
c) Using a hash code
d) Using a label
Answer:
b) Using an index
Explanation:
Elements in a Python array are accessed using an index.
3. Which module is commonly used for working with Python arrays?
a) array
b) list
c) collections
d) numpy
Answer:
a) array
Explanation:
The array module is commonly used for working with Python arrays.
4. What is the purpose of the append() method in Python arrays?
a) To remove an element from the array
b) To add an element to the end of the array
c) To insert an element at a specific index
d) To clear all elements from the array
Answer:
b) To add an element to the end of the array
Explanation:
The append() method is used to add an element to the end of a Python array.
5. How can you remove an element from a Python array by its value?
a) Using the pop() method
b) Using the remove() method
c) Using slicing
d) Using the delete() method
Answer:
b) Using the remove() method
Explanation:
The remove() method is used to remove an element from a Python array by its value.
6. What is the purpose of the pop() method in Python arrays?
a) To push an element onto the array
b) To remove and return the last element of the array
c) To remove and return the first element of the array
d) To clear all elements from the array
Answer:
b) To remove and return the last element of the array
Explanation:
The pop() method removes and returns the last element of a Python array.
7. Which method is used to check if an element exists in a Python array?
a) find()
b) in
c) contains()
d) exists()
Answer:
b) in
Explanation:
You can check if an element exists in a Python array using the in keyword.
8. Which method is used to sort a Python array in ascending order?
a) sort()
b) reverse()
c) sorted()
d) shuffle()
Answer:
a) sort()
Explanation:
The sort() method is used to sort a Python array in ascending order.
9. How can you reverse the order of elements in a Python array?
a) Using the sort() method with reverse=True
b) Using the reverse() method
c) Using the reversed() function
d) Using a loop
Answer:
b) Using the reverse() method
Explanation:
The reverse() method is used to reverse the order of elements in a Python array.
10. Which method is used to clear all elements from a Python array?
a) clear()
b) delete()
c) pop()
d) remove_all()
Answer:
a) clear()
Explanation:
The clear() method is used to clear all elements from a Python array.
11. What is the time complexity of accessing an element in a Python array by index?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
Answer:
a) O(1)
Explanation:
Accessing an element in a Python array by index has a time complexity of O(1).
12. Which data structure is used to implement Python arrays?
a) Linked list
b) Dynamic array
c) Hash table
d) Queue
Answer:
b) Dynamic array
Explanation:
Python arrays are implemented as dynamic arrays.
13. What is the primary purpose of using arrays in Python?
a) To create a collection of key-value pairs
b) To represent a stack data structure
c) To store and manipulate a collection of elements efficiently
d) To store elements in a random order
Answer:
c) To store and manipulate a collection of elements efficiently
Explanation:
The primary purpose of using arrays in Python is to store and manipulate a collection of elements efficiently.
14. Which module provides support for numerical arrays and mathematical operations in Python?
a) array
b) math
c) numpy
d) statistics
Answer:
c) numpy
Explanation:
The numpy module provides support for numerical arrays and mathematical operations in Python.
15. What is the result of using the extend() method to add elements from one array to another?
a) The original array is modified to include the elements from the second array.
b) A new array is created with elements from both arrays.
c) The second array is cleared, and its elements are added to the first array.
d) An error is raised because the extend() method is not supported in Python.
Answer:
a) The original array is modified to include the elements from the second array.
Explanation:
The extend() method modifies the original array to include elements from the second array.
16. Which method is used to insert an element at a specific index in a Python array?
a) add()
b) insert()
c) append()
d) put()
Answer:
b) insert()
Explanation:
The insert() method is used to insert an element at a specific index in a Python array.
17. How can you find the index of the first occurrence of an element in a Python array?
a) Using the search() method
b) Using the index() method
c) Using the find() method
d) Using the locate() method
Answer:
b) Using the index() method
Explanation:
The index() method is used to find the index of the first occurrence of an element in a Python array.
18. Which method is used to count the number of occurrences of an element in a Python array?
a) count()
b) find()
c) search()
d) locate()
Answer:
a) count()
Explanation:
The count() method is used to count the number of occurrences of an element in a Python array.
19. What is the result of using the copy() method to create a copy of a Python array?
a) A shallow copy of the original array is created.
b) A deep copy of the original array is created.
c) The original array is cleared, and its elements are copied to a new array.
d) An error is raised because the copy() method is not supported in Python.
Answer:
a) A shallow copy of the original array is created.
Explanation:
The copy() method creates a shallow copy of the original array.
20. Which method is used to remove the element at a specific index in a Python array?
a) pop()
b) remove()
c) delete()
d) clear()
Answer:
a) pop()
Explanation:
The pop() method is used to remove the element at a specific index in a Python array.
MCQ
Related Python Source Code Examples:
Python string literals
Python string length example
Python String join() method example
Python string split() method example
Python String index() method example
Python string find() method example
Python string startswith() method example
Python string endswith() method example
Python String lower() method example
Python String upper() method example
Python string title() method example
Python string capitalize() method example
Python string islower() method example
Python string istitle() method example
Python string isupper() method example
Python string swapcase() method example
Python string strip() method example
Python string replace() method example
Python string isdigit() method example
Python string isdecimal() method example
Python string isnumeric() method example
Python string isalpha() method example
Python string isalnum() method example
Write a python program to concatenate strings in different ways
Python program to create a new string by appending s2 in the middle of s1
Split a given string on asterisk into several substrings and display each substring in Python
Write a Python program to count all lower case, upper case, digits, and special symbols from a given string
Write a python program to return a string such that the string is arranged from lowercase letters and then uppercase letters
Write a Python Class to Reverse a String Word by Word
Write a python class to implement pow(x, n)
Write a python class to convert an integer to a Roman numeral
Write a python program to find the factorial of a number using recursion
Write a Python program to convert temperature in Celsius to Fahrenheit
Write a Python program to find the largest number among the three input numbers
Write a Python program to print only even numbers using the function
Write a python program to filter integer, float, string from a list
Write a python program to check whether the given number is greater than 50 and also divisible by 2 using nested if else
Write a python program to demonstrate a simple class creation
Write a python program to demonstrate the object as an argument
Write a python program to demonstrate an object as an argument with default values
Write a python program to demonstrate method overriding
Write a Python program for Linear Search and Binary Search
Python list - insert, remove, append, len, pop and clear example
Write a python program to add two numbers
Write a python program to get the python version
Write a python program to check whether the first and last letters of the given word is vowel or not ?
Write a python program to count the number of digits
Write a python program to filter integer, float, string from a list
Write a python program to find the average of 10 numbers
Write a python program to traverse a list and print the values in it
Write a python program to print first 20 natural numbers using while loop
Write a python program to print the square of all numbers from 1 to 10
Write a python program to get the sum of digits
Write a python program to print right angle triangle pattern using *
Write a python program to remove vowels in a word
Write a python program to find absolute value using function
Wrtie a python program to demonstrate the use of variable length arguments
Write a python program to demonstrate the use of default arguments
Write a python program to demonstrate the use of keyword arguments
Write a python program to print a simple list using functions
Write a python program to find the max values in a list using function
Given a string of odd length greater 7, return a string made of the middle three chars of a given String
Arrange string characters such that lowercase letters should come first
Write a Python program to Count all lower case, upper case, digits, and special symbols from a given string
Write a Python program to Find all occurrences in a given string ignoring the case
Given an input string, count occurrences of all characters within a string and return the details as dictionary
Write a Python program to Split a given string on asterisk into several substrings and display each substring
Write a Python program to Check whether the given string startswith 'h'
Write a python program to concatenate strings in different ways
Write a python program to return a string such that the string is arranged from lowercase letters and then uppercase letters
Write a python program to repeat a givent string multiple times
Write a python program to create a simple list and nested list with different datatypes
Write a python program to add elements to an existing list from user input
Write a python program to reverse a given list
Write a python program to convert a list to tuple using tuple function
Write a python program to check whether the user given input is equal to the current working directory or not
Write a Python program for Linear Search and Binary Search
Selection Sort Algorithm in Python
Bubble Sort Algorithm in Python
Bogo Sort Algorithm in Python
Bucket Sort Algorithm in Python
Comb Sort Algorithm in Python
Counting Sort Algorithm in Python
Heap Sort Algorithm in Python
Insertion Sort Algorithm in Python
Merge Sort Algorithm in Python
Quick Sort Algorithm in Python
Shell Sort Algorithm in Python
Interpolation Search Algorithm in Python
Stack Implementation in Python
Queue Implementation in Python
Deque Implementation in Python
Singly Linked List Implementation in Python
Doubly Linked List Implementation in Python
Circular Linked List Implementation in Python
PriorityQueue Implementation in Python
Circular Queue Implementation in Python
Binary Search Tree Implementation in Python
Stack Implementation Using Linked List in Python
Stack Implementation Using Doubly Linked List in Python
Python - Convert Binary to Decimal Example
Python - Convert Binary to Hexadecimal Example
Python - Convert Binary to Octal Example
Python - Convert Decimal to Binary Example
Python - Convert Decimal to Octal Example
Python Convert String to Int
Python Convert String to DateTime
Python Convert String to Date
Python Convert String to JSON
Python Convert String to Number
Python Convert String to List
Python Convert String to Float
Python Convert String to Bytes
Python Convert List to String
Python Convert List to Set
Python Convert List to Dictionary
Python Convert List to Tuple
Python Convert List to JSON
Python Convert List to Array
Python Convert List to String With Commas
Python Convert List to Dataframe
Python Convert Set to List
Python Convert Set to String
Python Convert Set to Tuple
Python Convert Set to Dictionary
Python Convert Set to JSON
Python Convert Set to Comma Separated String
Python Convert Dictionary to JSON
Python Convert Dictionary to Dataframe
Python Convert Dictionary to String
Python Convert Dictionary to List
Python Convert Dictionary Keys to List
Python Convert Dictionary Values to List
Python Convert Dictionary to Tuple
Python Convert Array to String
Python Convert Array to String With Commas
Python Convert Array to List
Python Convert Array to Set
Python Convert Array to JSON
Python Convert Array to Dictionary
Python Convert Array to Tuple
Python Convert Int to String
Python Convert Int to Binary
Python Convert Int to Float
Python Convert Date to String
Python Convert Date to Epoch
Python Convert Date to Unix Timestamp
Python Convert Date to DateTime
Python Convert Date to DateTime
Python Convert Date to Timestamp
Python Convert Date String to DateTime
Python Convert Date String to Epoch
Python Convert Tuple to String
Python Convert Tuple to List
Python Convert Tuple to Dictionary
Python Convert Tuple to Comma Separated String
Python Convert Tuple to Array
Python Convert Tuple to JSON
Python Convert JSON to String
Python Convert JSON to Dictionary
Python Convert JSON to Array
Python Convert JSON to XML
Python Convert JSON to List
Python
Comments
Post a Comment