Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Basic Python MCQs

This document contains a series of multiple-choice questions (MCQs) related to Python programming, covering topics such as data types, operators, and the Python Virtual Machine (PVM). Each question is followed by multiple answer options, with the correct answers indicated. The document serves as a quiz or study guide for individuals looking to test or enhance their knowledge of Python.

Uploaded by

Vikram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Basic Python MCQs

This document contains a series of multiple-choice questions (MCQs) related to Python programming, covering topics such as data types, operators, and the Python Virtual Machine (PVM). Each question is followed by multiple answer options, with the correct answers indicated. The document serves as a quiz or study guide for individuals looking to test or enhance their knowledge of Python.

Uploaded by

Vikram
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Basic Python MCQs 7. What will be the output of the following expression: 4 + 3 % 5?

1. Who developed Python Programming Language? a) 7


a) Wick van Rossum Answer: c) Guido van Rossum16 b) 2
b) Rasmus Lerdorf c) 4
c) Guido van Rossum d) 1
d) Niene Stom Answer: a) 71
2. Which type of programming does Python support? 8. Which function is used to read input from the console in Python?
a) Object-oriented programming a) input()
b) Structured programming b) scan()
c) Functional programming c) read()
d) All of the mentioned d) getInput()
Answer: d) All of the mentioned1 Answer: a) input()4
3. Is Python case-sensitive when dealing with identifiers? 9. What is the default data type returned by the input() function in
a) No Python 3.x?
b) Yes a) int
c) Machine dependent b) string
d) None of the mentioned c) boolean
Answer: b) Yes17 d) list
4. What is the correct extension for Python files? Answer: b) string4
a) .python 10. Which of these is an immutable data type in Python?
b) .pl a) List Answer: c) Tuple
c) .py b) Dictionary
d) .p c) Tuple
Answer: c) .py16 d) Set
5. What is the maximum length of a Python identifier? 1. What is PVM in Python?
a) 31 characters a) Python Variable Model
b) 63 characters b) Python Vernacular Machine
c) 79 characters c) Python Virtual Machine
d) No fixed length (depends on memory) d) Python VRAM Machine
Answer: d) No fixed length (depends on memory)27 Answer: c) Python Virtual Machine2
6. How is a block of code defined in Python? 2. What does the Python Virtual Machine (PVM) do?
a) Brackets a) Converts byte code to machine code
b) Indentation b) Interprets and runs byte code line by line
c) Key symbols like {} or [] c) Confined memory to safely run byte code
d) None of the above d) All of the above
Answer: b) Indentation16 Answer: d) All of the above2

pg. 1
3. The byte code produced after compiling a Python program is run 1. Which of these is not a core data type in Python?
inside ________. a) List
a) Java Virtual Machine b) Dictionary
b) Python Virtual Machine c) Tuple
c) DRAM d) Class
d) Static RAM Answer: d) Class1
Answer: b) Python Virtual Machine2 2. What is the data type of the following Python variable: x = 5?
4. Which part of PVM reclaims or releases memory that is no longer a) String
referenced by any variable? b) Integer
a) Memory Collector Answer: c) Garbage Collector2 c) Float
b) Garbage Bag d) Character
c) Garbage Collector Answer: b) Integer4
d) Recycle Bin 3. Which data type in Python is used to store a sequence of
5. The PVM is implemented as a ________. characters?
a) Heap memory structure Answer: b) Stack memory structure2 a) Tuple
b) Stack memory structure b) String
c) Both Heap and Stack memory structures c) List
d) None of the above d) Set
6. What type of code does a Python program generate after Answer: b) String4
compilation? 4. What data type would you use to store the value 3.14 in Python?
a) Cheat Code Answer: b) Byte Code2 a) Integer
b) Byte Code b) Float
c) Short Code c) String
d) Nano Code d) Complex
7. Which programming languages produce byte code similar to Answer: b) Float34
Python? 5. Which of the following is a mutable data type in Python?
a) Java and PHP only a) Tuple Answer: b) List5
b) Scala and Kotlin only b) List
c) All of the above (Python, Java, PHP, Scala, Kotlin, Groovy, etc.) c) String
d) None of the above d) Boolean
Answer: c) All of the above2 6. What is the data type of the following: ["apple", "banana",
8. What symbol is displayed in the Python Shell prompt? "cherry"]?
a) >> a) Dictionary
b) >>> b) Tuple
c): c) List
d):> 7. d) Set
Answer: b) >>> Answer: c) List3

pg. 2
8. Which of the following is an immutable data type in Python? 1. Which of the following is true about sets in Python?
a) List a) Sets are immutable
b) Dictionary b) Sets allow duplicate elements
c) Tuple c) Sets are unordered collections of unique elements
d) Set d) Sets are indexed collections of elements
Answer: c) Tuple45 Answer: c) Sets are unordered collections of unique elements
9. What is the data type of x = {"name": "John", "age": 30}? 2. Which of the following statements is used to create an empty set?
a) List a) {}
b) Dictionary b) set()
c) Set c) []
d) Tuple d) ( )
Answer: b) Dictionary4 Answer: b) set()
10. What is the data type of the following variable: x = 3.14j? 3. What will be the output of the following Python code?
a) Integer python
b) Float nums = set([1, 1, 2, 3, 3, 3, 4, 4])
c) Complex number print(len(nums))
d) String a) 7
Answer: c) Complex number4 b) Error: invalid syntax for set creation
11. Which of the following will run without errors? c) 4
a) round(45.8) d) 8
b) round(6352.898, 2, 5) Answer: c) 4
c) round() 4. Which of the following is not the correct syntax for creating a set?
d) round(7463.123, 2, 1) a) set([[1,[2],[3][4]])
Answer: a) round(45.8)1 b) set([1,[2][2][3][4])
12. What is the output of this code: str = "hello"; print(str[:2])? c) set((1, 2, 3, 4))
a) he d) {1, 2, 3, 4}
b) lo Answer: a) set([[1][2], [3,4]])
c) olleh 5. What happens when you execute the following code?
d) hello python
Answer: a) he1 a = {5, 6, 7}
13. Which Python data type is best suited for storing unique items? a.add(5)
a) List print(a)
b) Dictionary a) {5, 5, 6, 7}
c) Set b) {5, 6, 7}
d) Tuple c) Error: add() function does not exist for sets in Python
Answer: c) Set d) Error: Duplicate elements are not allowed in sets
MCQs on Python Sets Answer: b) {5, 6, 7}

pg. 3
6. What will be the output of the following Python code? d) None
python Answer: a) True
a = {4, 5, 6} Answer: a) {4, 5} 11. What will happen if you execute this code?
b = {2, 8, 6} s = {1, "hello", (2, 3)}
print(a - b) print(s)
a) {4, 5} a) Prints {1, "hello", (2,3)}
b) {6} b) Error: Mixed data types are not allowed in sets
c) Error: unsupported operand type for sets c) Error: Tuples cannot be added to sets
d) {4} d) None of the above
7. Which operator is used to perform the union of two sets in Answer: a) Prints {1, "hello", (2,3)}
Python? 12. Which of these operations is invalid for sets in Python?
a) + Answer: b) | a) Union using |
b) | b) Intersection using &
c) & c) Concatenation using +
d) - d) Symmetric difference using ^
8. What will be the output of the following Python code? Answer: c) Concatenation using +
python MCQs on Python Literals
a = {3, 4} Answer: b) {3, 5} 1. Which of the following is a valid Boolean literal in Python?
b = {4, 5} a) True
print(a ^ b) b) False
a) {3} c) None
b) {3, 5} d) Both a and b
c) {4} Answer: d) Both a and b
d) {3, 4} 2. Which of the following is an example of a string literal in Python?
9. If a = {1,2}, which of the following operations is invalid? a) "Hello, World!"
a) a.add(3) Answer: c) a b) 'Python'
b) a.remove(1) c) """Triple quotes"""
c) a d) All of the above
d) len(a) Answer: d) All of the above
10. What will be the result of the following code? 3. What type of literal is represented by 0xA in Python?
a = {1, 2} a) Binary literal
b = frozenset({2}) b) Hexadecimal literal
print(b.issubset(a)) c) Octal literal
a) True d) Decimal literal
b) False Answer: b) Hexadecimal literal
c) Error: frozensets cannot be subsets

pg. 4
4. Which of the following is not a valid numeric literal in Python? a) Error
a) 0b1010 b) newline
b) 0o123 c) new line
c) 123.45e+6 d) None of the above
d) 12,345 Answer: c) new line
Answer: d) 12,345 10. Which arithmetic operators cannot be used with string literals in
5. What will be the output of the following code snippet? Python?
print(0xA + 0xB + 0xC) a) +
a) 33 b) *
b) 0x22 c) -
c) Error: Invalid syntax for literals d) Both a and b
d) None of the above Answer: c) -
Answer: a) 33 MCQs on Operators in Python
6. Which of the following is an example of a complex number literal 1. Which operator is used for exponentiation in Python?
in Python? a) x^y
a) 3 + 4j b) x**y
b) 3.14j c) x^^y
c) 5j d) None of the mentioned
d) All of the above Answer: b) x**y1
Answer: d) All of the above 2. Which operator performs floor division in Python?
7. What does the prefix r indicate in string literals like r"\nhello"? a) /
a) Raw string (escape sequences are not processed) b) //
b) Recursive string processing c) %
c) Reverse string output d) None of the mentioned
d) None of the above Answer: b) //1
Answer: a) Raw string (escape sequences are not processed) 3. What is the precedence order of operators in Python?
8. Which type of literal does the following code represent? a) Parentheses, Exponential, Multiplication, Division, Addition,
python Subtraction
x = None b) Exponential, Parentheses, Multiplication, Division, Addition,
a) Boolean Literal Subtraction
b) Special Literal c) Parentheses, Exponential, Division, Multiplication, Addition,
c) String Literal Subtraction
d) Numeric Literal d) Parentheses, Exponential, Multiplication, Addition, Subtraction,
Answer: b) Special Literal Division
9. What will be the output of this code snippet? Answer: a) Parentheses, Exponential, Multiplication, Division,
python Addition, Subtraction1
print('new' 'line')

pg. 5
4. What is the result of the expression 22 % 3? 10. What is the result of this expression: 2**4 + (5 + 5)**(1 + 1)?
a) 7 a) 100
b) 1 b) 16
c) 0 c) 116
d) 5 d) None of the above
Answer: b) 11 Answer: c) 116
5. Can mathematical operations be directly performed on strings in MCQs on Arithmetic Operators in Python
Python without conversion? 1. Which operator is used for exponentiation in Python?
a) True Answer: b) False1 a) x^y
b) False b) x**y
6. Operators with the same precedence are evaluated in which c) x^^y
manner? d) None of the mentioned
a) Left to Right Answer: b) x**y1
b) Right to Left 2. Which operator performs floor division in Python?
c) Can’t say a) / Answer: b) //1
d) None of the mentioned b) //
Answer: a) Left to Right1 c) %
7. What is the output of this expression: 3 * 1**3? d) None of the mentioned
a) 27 Answer: c) 31 3. What is the output of the following Python command?
b) 9 python
c) 3 print(23.0 / 4) Answer: b) 5.752
d) None of the above a) 5.0
8. Which one of the following is not a valid operator in Python? b) 5.75
a) != (not equal to operator) c) 6.0
b) = (assignment operator) d) Error
c) =! (invalid syntax for not equal to operator) 4. What is the result of the expression 22 % 3?
d) // (floor division operator) a) 7 Answer: b) 13
Answer: c) =!3 b) 1
9. What will be the output of this code snippet? c) 0
python d) 5
print(type(5 / 2)) 5. Which arithmetic operators cannot be used with strings in
print(type(5 // 2)) Python?
a) Float and Int a) *
b) Int and Int b) +
c) Float and Float c) -
d) None of the above d) All of the mentioned
Answer: a) Float and Int3 Answer: c) -5

pg. 6
6. What will be the output of this code snippet? Relational Operators
print(type(5 / 2)) 1. Which of the following is a relational operator in Python?
print(type(5 // 2)) a) +
a) Float and Int b) ==
b) Int and Int c) and
c) Float and Float d) is
d) None of the above Answer: b) ==
Answer: a) Float and Int2 2. What will be the output of the following code?
7. What is the precedence order of arithmetic operators in Python? python
a) Parentheses, Exponential, Multiplication, Division, Addition, print(5 >= 3)
Subtraction a) True
b) Exponential, Parentheses, Multiplication, Division, Addition, b) False
Subtraction c) None
c) Parentheses, Exponential, Division, Multiplication, Addition, d) Error
Subtraction Answer: a) True
d) Parentheses, Exponential, Multiplication, Addition, Subtraction, 3. Which relational operator checks if two values are not equal?
Division a) =
Answer: a) Parentheses, Exponential, Multiplication, Division, b) !=
Addition, Subtraction1 c) <
8. What will be the result of this expression: 2**4 + (5 + 5)**(1 + 1)? d) >
a) 100 Answer: b) !=
b) 16 Logical Operators
c) 116 4. Which of the following is a logical operator in Python?
d) None of the above a) and
Answer: c) 11623 b) or
9. Which operator is used to return only the integer part of division c) not
in Python? d) All of the above
a) / Answer: b) //5 Answer: d) All of the above
b) // 5. What will be the output of this expression?
c) % python
d) None of the above True and False or True
10. What does the modulo operator % do in Python? a) True
a) Divides two numbers and returns an integer result b) False
b) Divides two numbers and returns a float result c) None
c) Divides two numbers and returns the remainder d) Error
d) None of the above Answer: a) True
Answer: c) Divides two numbers and returns the remainder

pg. 7
6. What does the not operator do in Python? 11. Which bitwise operator shifts bits to the left in Python?
a) Inverts the value of a Boolean expression a) >> Answer: b) <<
b) Performs bitwise negation b) <<
c) Adds two numbers together c) &
d) None of the above d) |
Answer: a) Inverts the value of a Boolean expression 12. Which membership operator checks if an element exists in a
Boolean Operators sequence?
7. Which of these is not a Boolean value in Python? a) is Answer: b) in
a) True b) in
b) False c) not in
c) None d) None of the above
d) 0 13. What will be the output of this code snippet?
Answer: c) None python
8. What will be the output of this code snippet? x = "Python"
python print("y" in x)
print(bool([])) a) True
a) True b) False
b) False c) Error: Invalid syntax for membership operator
c) Error: Invalid syntax for bool() function d) None of the above
d) None of the above Answer: b) False
Answer: b) False Identity Operators
Bitwise Operators 14. What does the identity operator is check in Python?
9. Which bitwise operator is used to perform XOR in Python? a) If two variables have the same value
a) & b) If two variables refer to the same memory location
b) | c) If two variables are different objects
c) ^ d) None of the above
d) ~ Answer: b) If two variables refer to the same memory location
Answer: c) ^ 15. What will this code snippet return?
10. What is the result of this expression? python
python x = [1, 2, 3]
4 ^ 12 y = [1, 2, 3]
a) 4 print(x is y)
b) 8 a) True
c) 16 b) False
d) 12 c) Error: Invalid syntax for identity operators
Answer: b) 8 d) None of the above
Answer: b) False

pg. 8
16. Which identity operator checks if two objects are not identical? Loops (for, while)
a) != Answer: c)is not 5. Which of the following is not used as a loop in Python?
b)not is a) for
c)is not b) while
d)<> c) do-while
Which of the following keywords is used to add an alternative d) None of the above
condition to an if statement? Answer: c) do-while
a) else if Answer: c) elif 6. What will be the output of this code?
b) elseif for i in range(5):
c) elif print(i, end=" ")
d) All of the above a) 0 1 2 3 4
1. What will be the output of the following code? b) 1 2 3 4 5
python c) Error: Invalid syntax for range() function
x = 10 d) None of the above
if x > 5 and x < 15: Answer: a) 0 1 2 3 4
print("x is between 5 and 15") 7. What happens when the condition in a loop becomes false?
else: a) The loop terminates
print("x is outside the range") b) The loop restarts from the beginning
a) x is between 5 and 15 c) The loop skips that iteration and continues with the next one
b) x is outside the range d) None of the above
c) Error: Invalid syntax Answer: a) The loop terminates
d) None of the above 8. What will be the output of this code?
Answer: a) x is between 5 and 15 i=1
2. An if condition inside another if condition is called: while i < 4:
a) Nested if Answer: a) Nested if print(i)
b) Inner if i += 1
c) Chained if a) Infinite loop printing 1 repeatedly
d) None of the above b) 1 2 3
3. What is the output of this code? c) Error: Syntax issue with += operator
if 'a' == "a": d) None of the above
print(True) Answer: b) 1 2 3
else: Special Control Flow Keywords (break, continue, pass)
print(False) 9. What does the break statement do in Python?
a) True a) Skips to the next iteration of a loop
b) False b) Exits from the current loop immediately
c) Error: Mismatched quotesd) None of the above c) Stops program execution entirelyd) None of the above
Answer: a) True Answer: b) Exits from the current loop immediately

pg. 9
10. What will be the output of this code? 15. If a while loop's condition never becomes false, what happens?
for i in range(5): a) The program crashes
if i == 3: b) The loop runs indefinitely (infinite loop).
break c) The program skips that loop entirely
print(i, end=" ") d) None of these
a) Infinite loop printing numbers repeatedly Answer: b) The loop runs indefinitely (infinite loop).
b) 0 1 2
c) Error: Invalid syntax for break statement 1. What is an array in Python?
d) None of the above a) A collection of elements of different data types
Answer: b) 0 1 2 b) A collection of elements of the same data type
11. What does the continue statement do in Python? c) A collection of key-value pairs
a) Exits from the current loop immediately d) None of the above
b) Skips to the next iteration of a loop Answer: b) A collection of elements of the same data type
c) Stops program execution entirely
d) None of the above 2. How do you import the array module in Python?
Answer: b) Skips to the next iteration of a loop a) import arrays
12. Which statement acts as a null operation in Python? b) import array
a) break c) from array import *
b) continue d) import ArrayModule
c) pass Answer: b) import array
d) None of the above
Answer: c) pass 3. Which of the following is the correct way to create an array in
Miscellaneous Python?
13. How many elif statements can you use in an if-elif-else construct? a) myArray =[1][2][3]
a) Only one b) myArray = array.array('i', [1,2][3])
b) Two c) myArray = (1, 2, 3)
c) Unlimited, as needed d) myArray = {1, 2, 3}
d) None of these Answer: b) myArray = array.array('i', [1,2][3])
Answer: c) Unlimited, as needed
14. What will be printed by this code? 4. What does the typecode in an array define?
for i in range(3): a) The size of the array
pass b) The data type of the elements in the array
print("Loop completed") c) The name of the array
a) Loop completed d) None of the above
b) Error: Missing body for for loop Answer: b) The data type of the elements in the array
c) Nothing gets printedd) None of these
Answer: a) Loop completed

pg. 10
5. What will be the output of the following code? 10. What will be the output of this code snippet?
import array python
myArray = array.array('i', [1, 2, 3]) import array
myArray.append(4) arr = array.array('i', [10, 20, 30])
print(myArray) print(arr[1])
a) [1,[2][3] a) Error: Invalid syntax for accessing an element in an array
b) [1, 2, 3,[4] b) 10
c) array('i', [1,2][3]) c) 20
d) array('i', [1,2][3][4]) d) None of these
Answer: d) array('i', [1,2][3][4]) Answer: c) 20
6. How do you find the index of the first occurrence of an element in 11. Which method is used to add multiple elements to an existing
an array? Python array?
a) find() a) append()
b) index() b) extend()
c) search() c) insert()
d) None of the above d) None of these
Answer: b) index() Answer: b) extend()
7. What does the reverse() method do in an array? 12. What will happen if you try to access an index that is out of range
a) Sorts the elements in descending order in a Python array?
b) Reverses the order of elements in the array a) Returns None
c) Removes duplicate elements from the array b) Throws an IndexError
d) None of the above c) Returns False
Answer: b) Reverses the order of elements in the array d) None of these
8. Which method is used to remove a specific element from an Answer: b) Throws an IndexError
array? MCQs on Python Slicing
a) delete() 1. What is slicing in Python?
b) remove() a) Dividing a string into multiple parts
c) pop() b) Extracting a portion of a sequence
d) None of the above c) Removing elements from a sequence
Answer: b) remove() d) Changing the order of elements in a sequence
9. Can you change the value of an existing element in an array? Answer: b) Extracting a portion of a sequence
a) Yes 2. Which syntax is correct for slicing in Python?
b) No a) sequence[start:end:step]
c) Only for numeric arrays b) sequence[start:end]
d) Only for string arrays c) sequence[start:]
Answer: a) Yes d) All of the above
Answer: d) All of the above

pg. 11
3. What will be the output of the following code? 8. What is the output of this code?
word = "Python" s = "Pythonista"
print(word[0:3]) print(s[6:2:-1])
a) Pyt a) ohni
b) Py b) ino
c) thon c) istan
d) None of the above d) None of the above
Answer: a) Pyt Answer: a) ohni
4. What does slicing with [::-1] do in Python? 9. Which slicing syntax extracts every second element from index 0
a) Reverses the sequence to 6?
b) Extracts every second element from the sequence a) sequence[0:6:2]
c) Removes elements from the sequence b) sequence[::2]
d) None of the above c) sequence[0:6:-2]
Answer: a) Reverses the sequence d) sequence[:6:2]
5. What will be the output of this code? Answer: a) sequence[0:6:2]
nums = [1, 2, 3, 4, 5] 10. What will be printed by this code snippet?
print(nums[1:4]) s = "Subscribe"
a) [1,2]3 print(s[4:5])
b) [2,3]4 a) Blank Output
c) [3,4]5 b)s
d) None of the above cError
Answer: b)234 MCQs on Strings and Characters in Python
6. What happens if the step value in slicing is set to 0? Basic String Operations
a) Returns an empty sequence 1. How do you create a string in Python?
b) Throws a ValueError a) Enclose characters in single quotes
c) Returns the original sequence unchanged b) Enclose characters in double quotes
d) None of the above c) Enclose characters in triple quotes
Answer: b) Throws a ValueError d) All of the above
7. What will be printed by this code snippet? Answer: d) All of the above13
s = "Amazing" 2. What is the output of len("Python")?
print(s[-4:-1]) a) 5
a) azi b) 6
b) zing c) 7
c) amazi d) None of the above
d) None of the above Answer: b) 61
Answer: b) zing

pg. 12
3. How do you access the first character of a string s = "Python"? 1. How do you create a string in Python?
a) s a) Enclose characters in single quotes
b) s[1] b) Enclose characters in double quotes
c) s[-1] c) Enclose characters in triple quotes
d) None of the above d) All of the above
Answer: a) s14 Answer: d) All of the above12
4. What is slicing in Python? 2. What is the output of len("Python")?
a) Extracting a portion of a string using indices a) 5
b) Concatenating strings together b) 6
c) Removing characters from a string c) 7
d) None of the above d) None of the above
Answer: a) Extracting a portion of a string using indices14 Answer: b) 61
5. What does "Hello" + "World" return in Python? 3. How do you access the first character of a string s = "Python"?
a) Hello World a) s
b) HelloWorld b) s[1]
c) Error: Cannot concatenate strings without space c) s[-1]
d) None of the above d) None of the above
Answer: b) HelloWorld1 Answer: a) s1
String Methods 4. What is slicing in Python?
6. What is the output of "python".capitalize()? a) Extracting a portion of a string using indices
a) Python b) Concatenating strings together
b) PYTHON c) Removing characters from a string
c) python d) None of the above
d) None of the above Answer: a) Extracting a portion of a string using indices12
Answer: a) Python13 String Operations
7. Which method converts all characters in a string to lowercase? 5. What does "Hello" + "World" return in Python?
a) upper() a) Hello World
b) lower() b) HelloWorld
c) capitalize() c) Error: Cannot concatenate strings without space
d) None of the above d) None of the above
Answer: b) lower()34 Answer: b) HelloWorld1
8. How do you replace "Python" with "Java" in "I love Python"? 6. What is the result of 'Py' * 3 in Python?
a) replace("Python", "Java") a) PyPyPy
b)`replace("Java","Python") b) Py3
c) Error: Cannot multiply strings by integers
MCQs on Basics of Strings in Python d) None of the above
String Creation and Access Answer: a) PyPyPy1

pg. 13
7. Which operator is used to check if a substring exists within a 17. What is the index of the first element in a Python list?
string? a) 0
a) in b) 1
b) contains() c) -1
c) find() d) None of the above
d) None of the above Answer: a) 0
Answer: a) in12 18. What will be the output of this code?
String Methods my_list = [1, 2, 3]
8. What does "python".capitalize() return? print(len(my_list))
a) Python a) 2
b) PYTHON b) 3
c) python c) Error: Invalid syntax for len() function
d) None of the above d) None of the above
Answer: a) Python12 Answer: b) 3
9. Which method converts all characters in a string to lowercase? 19. Which method adds an element to the end of a list?
a) upper() a) extend() Answer: b) append()
b) lower() b) append()
c) capitalize() c) insert()
d) None of the above d) None of the above
Answer: b) lower()2 20. Which method removes all elements from a list?
10. How do you replace "Python" with "Java" in "I love Python"? a) clear() Answer: a) clear()
MCQs on Lists in Python b) delete()
11. Basic List Operations c) remove()
12. Which of the following commands will create a list? d) None of the above
a) list1 = list() 21. What does the count() method do in a list?
b) list1 = [] a) Counts the total number of elements in the list
c) list1 = list([1][2][3]) b) Counts occurrences of a specific element in the list
d) All of the above c) Counts unique elements in the list
Answer: d) All of the above d) None of the above
13. What is the output of the following code? Answer: b) Counts occurrences of a specific element in the list
14. python 22. Which method is used to insert an element at a specific index in a
15. list("hello") list?
16. a) ['h', 'e', 'l', 'l', 'o'] a) append()
b) ['hello'] b)insert()
c) ['llo'] c)extend()
d) None of the above 23. d)add()
Answer: a) ['h', 'e', 'l', 'l', 'o'] Answer: b)insert()

pg. 14
24. What will be printed by this code snippet? 29. What will be printed by this code snippet?
python python
my_list = [1, 2, 3] L = [10, 20, 30]
my_list.append([4, 5]) L[1] = "Python"
print(my_list) print(L)
a)[1,[2][3][4][5] a)[10, "Python", 30]
b)[1, 2, 3, [4,5]] b
c)[4][5] 30. Which of the following is a Python tuple?
d)Error a) [1][2][3]
Answer: b)[1, 2, 3, [4,5]] b) (1, 2, 3)
25. How can you combine two lists into one in Python? c) {1, 2, 3}
a)list1 + list2 d) {}
b)list1.extend(list2) Answer: b) (1, 2, 3)
c)Both (a) and (b) 31. What does it mean that tuples are immutable?
d)None of the above a) Elements can be changed after creation
Answer: c)Both (a) and (b) b) Elements cannot be changed after creation
26. What will be printed by this code snippet? c) Tuples can contain only integers
python d) None of the above
L = [1, 2, 3] Answer: b) Elements cannot be changed after creation
print(L[-1]) 32. Which of the following creates an empty tuple?
a)1 a) t = []
b)2 b) t = ()
c)3 c) t = tuple()
d)Error: Negative indexing is not allowed in lists. d) Both b and c
Answer: c)3 Answer: d) Both b and c
27. Which operator is used to repeat elements in a Python list? 33. What is the output of the following code?
a)* python
b)+ t = tuple("Python")
c)- print(t)
d)/ a) ('Python')
Answer: a)* b) ('P', 'y', 't', 'h', 'o', 'n')
28. What does slicing with [::2] do to a list? c) [P, y, t, h, o, n]
a) Reverses the list. d) None of the above
b) Selects every second element from the list. Answer: b) ('P', 'y', 't', 'h', 'o', 'n')
c) Removes duplicate elements from the list.
d )None of the above.
Answer: b)Selects every second element from the list.

pg. 15
34. Which operator is used to concatenate two tuples? 44. What will be the output of this code snippet?
a) + Answer: a) + 45. python
b) * 46. t = (1, 2, 3)
c) & 47. print(sorted(t))
d) None of the above 48. a)[1,23
35. What will be the output of this code snippet? b)(1, 2, 3)
python c)[3, 2,1
t1 = (1, 2) d)None of the above
t2 = (3, 4) Answer: a)123
print(t1 + t2) 49. Tuples can contain elements of which data type?
a) (1, 2) a)Numbers only
b)(3, 4) b)Strings only
c)(1, 2, 3, 4) c)Any data type
d)None of the above d)None of the above
Answer: c)(1, 2, 3, 4) Answer: c)Any data type
36. Which method returns the number of occurrences of an element 50. What will happen if you try to modify an element in a tuple?
in a tuple? a)The element will be modified successfully.
a)count() b)An error will occur because tuples are immutable.
b)index() c)The tuple will automatically convert to a list.
c)len() d)None of the above.
d)None of the above Answer: b)An error will occur because tuples are immutable.
Answer: a)count() 51. MCQs on Dictionaries in Python
37. What will be printed by this code snippet? 52. Basics of Dictionaries
38. python 53. What is a dictionary in Python?
39. t = (10, 20, 30) a) A collection of unique elements
40. print(t[1]) b) A collection of key-value pairs
41. a)10 c) A collection of ordered elements
b)20 d) None of the above
c)30 Answer: b) A collection of key-value pairs
d)Error: Negative indexing is not allowed in tuples. 54. Which symbol is used to separate keys and values in a dictionary?
Answer: b)20 a) :
42. Advanced Concepts b) =
43. Which function returns the length of a tuple? c) ,
a)length() d) None of the above
b)len() Answer: a) :
c)size()d)None of the above
Answer: b)len()

pg. 16
55. Which syntax correctly creates an empty dictionary? 61. What will be printed by this code snippet?
a) d = [] python
b) d = () d = {"a": 1, "b": 2}
c) d = {} print("a" in d)
d) d = set() a)True
Answer: c) d = {} b)False
56. What will be the output of the following code? c)Error: Invalid syntax for membership check.
python d)None of the above.
d = {"name": "John", "age": 25} Answer: a)True
print(d["name"])
a) John 62. Which function returns the number of key-value pairs in a
b) name dictionary?
c) Error: Invalid syntax for accessing dictionary elements a)len()
d) None of the above b)size()
Answer: a) John c)count()
57. Dictionary Operations d)None of the above
58. Which method is used to remove an element from a dictionary by Answer: a)len()
its key?
a) delete() 63. What happens if you try to access a key that does not exist in the
b) pop() dictionary?
c) remove() python
d) None of the above d = {"x": 10, "y": 20}
Answer: b) pop() print(d["z"])
59. Which method returns all the keys in a dictionary? a)Returns None
a) keys() b)Throws KeyError
b) values() c)Returns False
c) items() d)None of the above
d) None of the above Answer: b)Throws KeyError
Answer: a) keys()
60. What does the update() method do in a dictionary? 64. Can dictionaries have duplicate keys?
a)Adds new key-value pairs or updates existing ones. a)Yes
b)Removes all elements from the dictionary. b)No
c)Returns all keys as tuples. c)Only if they are strings.
d)None of the above. d)None of the above.
Answer: a)Adds new key-value pairs or updates existing ones. Answer: b)No
65.
66. What will be printed by this code snippet?

pg. 17
python Here is a detailed comparison of Set, List, Tuple,
d = {"A": "Apple", "B": "Ball"} and Dictionary in Python:
print(d.get("C"))
67. a)KeyNotFoundError Feature List Tuple Set Dictionary
b)None
c)Error: Invalid syntax for get() method. Ordered Ordered Unordered
d)C collection of collection of collection of unique Unordered collection
Answer: b)None Definition elements elements elements of key-value pairs
68. Which statement correctly merges two dictionaries, D1 and D2?
a)D1.append(D2) Syntax [ ] ( ) { } {key: value}
b)D1.update(D2)
c)D1.merge(D2)
d)D1.add(D2) Maintains Maintains Does not maintain Does not maintain
Answer: b)D1.update(D2) Order order order order order
69. What does the following code return?
70. python
Immutable
71. D = {1: "One", 2: "Two", 3: "Three"} Mutable (elements Mutable (elements Mutable (keys and
72. print(D.items()) (elements can cannot be can be values can be
73. a)[(1, "One"), (2, "Two"), (3, "Three")] Mutability be changed) changed) added/removed) added/removed)
b){(1, "One"), (2, "Two"), (3, "Three")}
c)123
Duplicates Keys: No, Values:
d){'items'}
Allowed Yes Yes No Yes
Answer: a)[(1, "One"), (2, "Two"), (3, "Three")]
74. Keys in dictionaries must be:
a)Mutable Indexing Keys are used for
b)Immutable and Slicing Supported Supported Not supported accessing values
c)Strings only
d)None of the above.
General-
Answer: b)Immutable
purpose Fixed data that
collection of should not Unique and Key-value pairs for
Use Case elements change unordered data quick lookups

Example `[1, (1, 2, 3) {1, 2, 3} {"a": 1, "b": 2}

pg. 18
Key Differences b) Wes McKinney
c) James Gosling
75. Order and Indexing
d) Brendan Eich
1. Lists and tuples maintain the order of elements
Answer: b) Wes McKinney
and support indexing.
81. Which of the following command is used to install Pandas?
2. Sets and dictionaries do not maintain order
(prior to Python 3.7) and do not support a) install pandas
indexing. b) pip install pandas
76. Mutability c) pandas install
1. Lists and sets are mutable, meaning their d) python install pandas
contents can be modified after creation. Answer: b) pip install pandas
2. Tuples are immutable, meaning their contents 82. Which of the following is NOT a data structure in Pandas?
cannot be changed after creation. a) Series
3. Dictionaries are mutable but keys must remain b) DataFrame
immutable. c) Panel (deprecated in recent versions)
77. Duplicates d) Array
1. Lists and tuples allow duplicate elements. Answer: d) Array
2. Sets do not allow duplicates. Pandas Series
3. Dictionaries do not allow duplicate keys but 83. What is a Pandas Series?
allow duplicate values. a) A one-dimensional labeled array capable of holding data of any
78. Use Cases type
1. Use lists when you need an ordered collection b) A two-dimensional labeled data structure with rows and columns
with duplicates. c) A three-dimensional data structure for panel data analysis
2. Use tuples when you need an immutable d) None of the above
sequence. Answer: a) A one-dimensional labeled array capable of holding data
3. Use sets for unique and unordered collections. of any type
4. Use dictionaries for key-value pair storage with 84. Which method is used to create a Pandas Series?
fast lookups. a) series()
MCQs on Pandas in Python b) Series()
79. What is Pandas in Python? c) create_series()
a) A library for data manipulation and analysis d) None of the above
b) A library for creating visualizations Answer: b) Series()
c) A library for numerical computations
d) None of the above
Answer: a) A library for data manipulation and analysis

80. Who developed the Pandas library? 85. What will be the output of this code snippet?
a) Guido van Rossum python

pg. 19
import pandas as pd import pandas as pd
s = pd.Series([10, 20, 30], index=['a', 'b', 'c']) df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
print(s['b']) print(df.shape)
a) 10 a)(2, 2)
b) 20 b)(4, 2)
c) 30 c)(2, 4)
d) Error: Invalid syntax for accessing Series elements d)Error: Invalid syntax for DataFrame creation.
Answer: b) 20 Answer: a)(2, 2)
86. Which attribute is used to get the index labels of a Pandas Series? 90. How can you display the first five rows of a DataFrame?
a) labels a)df.head()
b) index b)df.first(5)
c) columns c)df.show(5)
d) None of the above d)None of the above
Answer: b) index Answer: a)df.head()
Pandas DataFrame Operations and Methods
87. What is a DataFrame in Pandas? 91. Which method is used to add new rows or append data to an
a) A one-dimensional labeled array capable of holding data of any existing DataFrame?
type a)append()
b) A two-dimensional labeled data structure with rows and columns b)add_rows()
c) A three-dimensional data structure for panel data analysis c)extend()
d) None of the above d)insert()
Answer: b) A two-dimensional labeled data structure with rows and Answer: a)append()
columns 92. What will be printed by this code snippet?
88. Which method is used to read data from a CSV file into a python
DataFrame? import pandas as pd
a) read_csv() df = pd.DataFrame({'A': [1, 2], 'B': [3, 4]})
b)read_csv_file() print(df['A'].sum())
c)csv_read() a)3
d)readfile_csv() b)6
Answer: a)read_csv() c)10
d)None of the above
Answer: a)3

93. Which function is used to check for missing values in Pandas?


89. What will be the output of this code snippet? a)is_missing()
python b)isnull()

pg. 20
c)check_nulls()
d)None of the above
Answer: b)isnull()
94. What does the dropna() method do in Pandas?
a)Removes rows or columns with missing values.
b)Fills missing values with zeros.
c)Drops duplicate rows from the DataFrame.
d)None of the above.
Answer: a)Removes rows or columns with missing values.
95. Miscellaneous
96. Which statement correctly imports Pandas with an alias name?
a)import pandas as pd
b)import panda as pds
c)import pandas as pnd
d)All of the above
Answer: a)import pandas as pd
97. How can you get summary statistics (mean, median, etc.) for
numeric columns in a DataFrame?
a).describe()
b

pg. 21

You might also like