A) <class ‘list’>
B) <class ‘tuple’>
C) <class ‘dict’>
D) <class ‘set’>
View AnswerA
2. Which of the following is a mutable data type in Python?
A) Tuple
B) String
C) List
D) Int
View AnswerC
3. What keyword is used to define a function in Python?
A) function
B) def
C) define
D) func
View AnswerB
4. Which operator is used for exponentiation in Python?
A) ^
B) **
C) *
D) %
View AnswerB
5. How do you create a comment in Python?
A) // This is a comment
B) /* This is a comment */
C) # This is a comment
D) — This is a comment
View AnswerC
6. Which of the following is not a built-in data type in Python?
A) List
B) Dictionary
C) Array
D) Set
View AnswerC
7. What is the output of print(2 * 3 ** 2)?
A) 18
B) 12
C) 6
D) 9
View AnswerB
8. How do you start a while loop in Python?
A) while (condition)
B) while condition:
C) while: condition
D) loop while condition:
View AnswerB
9. Which method is used to add an item to a list in Python?
A) append()
B) add()
C) insert()
D) extend()
View AnswerA
10. What does the len() function do in Python?
A) Returns the length of a string
B) Returns the number of items in a list
C) Returns the size of a dictionary
D) All of the above
View AnswerD
11. How do you create a variable in Python?
A) variable = value
B) var variable = value
C) value -> variable
D) variable := value
View AnswerA
12. What is the purpose of the pass statement in Python?
A) To terminate a function
B) To indicate that no action is required
C) To exit a loop
D) To raise an exception
View AnswerB
13. What is the output of print(“Hello” + “World”)?
A) Hello World
B) HelloWorld
C) Hello, World
D) Error
View AnswerB
14. How do you check the type of an object in Python?
A) typeOf()
B) typeof()
C) type()
D) checktype()
View AnswerC
15. What is the default return value of a function in Python?
A) None
B) 0
C) “”
D) False
View AnswerA
16. Which of the following is used to handle exceptions in Python?
A) catch
B) try/except
C) handle
D) except/try
View AnswerB
17. Which statement is used to handle exceptions in Python?
A) try-catch
B) try-except
C) try-error
D) catch-exception
View AnswerB
18. What is the output of print(“abc”[1])?
A) a
B) b
C) c
D) Error
View AnswerB
19. Which function can be used to convert a string to an integer in Python?
A) int()
B) str()
C) float()
D) convert()
View AnswerA
20. Which of the following is a valid way to import a module in Python?
A) import module_name
B) import module_name as alias
C) from module_name import *
D) All of the above
View AnswerD
21. How can you get a substring in Python?
A) string[2:5]
B) string(2:5)
C) string{2:5}
D) string<2:5>
View AnswerA
22. What is the purpose of the init method in Python?
A) To initialize an instance of a class
B) To terminate a class
C) To define class variables
D) To call another function
View AnswerA
23. Which of the following is a Python built-in function?
A) print()
B) input()
C) len()
D) All of the above
View AnswerD
24. How do you start a for loop in Python?
A) for (variable in iterable):
B) for variable in iterable:
C) for: variable in iterable
D) loop for variable in iterable:
View AnswerB
25. Which statement is used to exit a loop in Python?
A) exit
B) break
C) continue
D) return
View AnswerB
26. What does the strip() method do?
A) Removes whitespace from the beginning and end of a string
B) Removes all characters from a string
C) Converts a string to lowercase
D) Splits a string into a list
View AnswerA
27. Which of the following is a mutable data type in Python?
A) Tuple
B) String
C) List
D) Int
View AnswerC
28. What will be the output of print(3 * ‘abc’)?
A) abcabcabc
B) abc abc abc
C) 3abc
D) Error
View AnswerA
29. How do you remove an item from a list in Python?
A) delete()
B) remove()
C) pop()
D) Both B and C
View AnswerD
30. Which keyword is used to define a class in Python?
A) class
B) def
C) type
D) new
View AnswerA
31. What is the correct way to create a function in Python?
A) function myFunction() {}
B) def myFunction():
C) create myFunction():
D) myFunction() = function
View AnswerB
32. Which of the following can be a key in a dictionary?
A) List
B) Tuple
C) Set
D) String
View AnswerD
33. What is the function of the map() method?
A) Applies a function to all items in an input list
B) Creates a list of numbers
C) Converts a string to a list
D) Filters a list based on a condition
View AnswerA
34. Which of the following is not a valid variable name in Python?
A) variable1
B) _variable
C) 1_variable
D) variable_name
View AnswerC
35. What does the keyword ‘self’ represent in a class?
A) The current instance of the class
B) A static method
C) A global variable
D) A local variable
View AnswerA
36. What is the correct way to create a list in Python?
A) list = (1, 2, 3)
B) list = [1, 2, 3]
C) list = {1, 2, 3}
D) list = <1, 2, 3>
View AnswerB
37. Which of the following methods can be used to add an element to a list in Python?
A) add()
B) append()
C) insert()
D) Both B and C
View AnswerD
38. What is the purpose of the filter() function?
A) To filter items from an iterable based on a function
B) To sort a list
C) To concatenate strings
D) To map values
View AnswerA
39. Which method is used to sort a list in Python?
A) sort()
B) order()
C) arrange()
D) organize()
View AnswerA
40. What is the output of print(type(()))?
A) <class ‘list’>
B) <class ‘tuple’>
C) <class ‘set’>
D) <class ‘dict’>
View AnswerB
41. What does the title() method do to a string?
A) Converts it to uppercase
B) Converts it to lowercase
C) Capitalizes the first letter of each word
D) Reverses the string
View AnswerC
42. How do you iterate through a dictionary in Python?
A) for key, value in dict.items():
B) for key in dict:
C) Both A and B
D) None of the above
View AnswerC
43. Which of the following is used to indicate the start of an indented block in Python?
A) Parentheses
B) Braces
C) Whitespace
D) Commas
View AnswerC
44. What is the method to get all keys from a dictionary?
A) keys()
B) all_keys()
C) get_keys()
D) list_keys()
View AnswerA
45. What will be the output of print(0 == False)?
A) True
B) False
C) None
D) Error
View AnswerA
46. Which of the following is a correct way to write a lambda function?
A) lambda x: x + 1
B) lambda(x): x + 1
C) def lambda x: x + 1
D) lambda: x + 1
View AnswerA
47. How do you create a new Python file?
A) file.create(“filename.py”)
B) open(“filename.py”, “w”)
C) create(“filename.py”)
D) new file(“filename.py”)
View AnswerB
48. What does the .append() method do?
A) Adds an item to the end of a list
B) Removes the last item from a list
C) Adds an item to the beginning of a list
D) Sorts a list
View AnswerA
49. Which of the following is used to read a file in Python?
A) read()
B) open()
C) load()
D) Both A and B
View AnswerD
50. How can you catch exceptions in Python?
A) using try/except
B) using catch
C) using handle
D) using except/try
View AnswerA
51. What is the correct way to create a class in Python?
A) class MyClass:
B) MyClass class:
C) define MyClass:
D) new class MyClass:
View AnswerA
52. What is the output of print(“5” + “5”)?
A) 10
B) 55
C) Error
D) 5 + 5
View AnswerB
53. Which of the following methods can be used to remove whitespace from the start and end of a string?
A) trim()
B) strip()
C) cut()
D) remove()
View AnswerB
54. What is the primary purpose of the str method in Python?
A) To define how an object should be represented as a string
B) To initialize an object
C) To create a class variable
D) To return the type of an object
View AnswerA
55. What will be the output of print(bool(“”))?
A) True
B) False
C) None
D) Error
View AnswerB
56. What keyword is used to define a function in Python?
A) func
B) define
C) def
D) function
View AnswerC
57. What does the input() function do in Python?
A) Takes user input from the console
B) Prints output to the console
C) Reads a file
D) None of the above
View AnswerA
58. Which of the following is a valid way to create a string in Python?
A) “Hello”
B) ‘Hello’
C) “””Hello”””
D) All of the above
View AnswerD
59. What will be the output of print(“Python”[0:2])?
A) Py
B) Pyt
C) Python
D) Error
View AnswerA
60. What is the output of print(5 % 2)?
A) 1
B) 2
C) 0
D) 5
View AnswerA
61. Which of the following keywords is used to define an iterator in Python?
A) iter
B) next
C) for
D) Both A and B
View AnswerD
62. How can you create a new list from an existing one?
A) new_list = old_list
B) new_list = list(old_list)
C) new_list = old_list[:]
D) Both B and C
View AnswerD
63. What does the join() method do in Python?
A) Joins a list of strings into a single string
B) Splits a string into a list
C) Concatenates two strings
D) None of the above
View AnswerA
64. How do you check if a key exists in a dictionary?
A) key in dict
B) dict.has_key(key)
C) key in dict.keys()
D) All of the above
View AnswerA
65. What is the output of print(4 == 4.0)?
A) True
B) False
C) None
D) Error
View AnswerA
66. Which of the following can be used to format strings in Python?
A) % operator
B) str.format() method
C) f-strings (from Python 3.6)
D) All of the above
View AnswerD
67. What is the purpose of the enumerate() function?
A) To add a counter to an iterable
B) To sort an iterable
C) To filter items from an iterable
D) To map values in an iterable
View AnswerA
68. How can you generate a random number in Python?
A) random.randint()
B) random.number()
C) random.generate()
D) random.random()
View AnswerA
69. What is the output of print(“abc”.upper())?
A) ABC
B) Abc
C) abc
D) Error
View AnswerA
70. Which function is used to create an object in Python?
A) new()
B) create()
C) init()
D) new()
View AnswerC
71. What is the purpose of the continue statement in loops?
A) To skip the current iteration and move to the next one
B) To terminate the loop
C) To exit the function
D) None of the above
View AnswerA
72. Which of the following is used to handle exceptions in Python?
A) try…catch
B) try…except
C) catch…finally
D) except…catch
View AnswerB
73. Which of the following functions is used to convert an integer to a string?
A) int()
B) str()
C) float()
D) list()
View AnswerB
74. What is the output of print(10 // 3)?
A) 3
B) 3.333
C) 4
D) 2
View AnswerA
75. What is the correct syntax for creating a lambda function that adds two numbers?
A) lambda x, y: x + y
B) def lambda x, y: x + y
C) lambda x, y = x + y
D) lambda x, y -> x + y
View AnswerA
76. How can you convert a list to a tuple in Python?
A) tuple(list)
B) list(tuple)
C) convert(list)
D) None of the above
View AnswerA
77. Which of the following will raise a SyntaxError?
A) print(“Hello”)
B) if x > 0:
C) for i in range(10)
D) def my_function():
View AnswerC
78. What does the list comprehension syntax [x for x in range(5)] do?
A) Creates a list of numbers from 0 to 4
B) Creates a list of even numbers
C) Creates a list of strings
D) None of the above
View AnswerA
79. Which of the following is used to handle exceptions in Python?
A) try/catch
B) try/except
C) except/catch
D) handle/try
View AnswerB
80. Which of the following is used to create a virtual environment in Python?
A) virtualenv
B) venv
C) pipenv
D) All of the above
View AnswerD
81. How do you import all functions from a module named ‘math’?
A) import math.*
B) from math import *
C) import all from math
D) None of the above
View AnswerB
82. What does the isinstance() function do?
A) Checks if an object is of a specified type
B) Converts an object to a specified type
C) Creates an instance of a class
D) None of the above
View AnswerA
83. How do you create a new dictionary in Python?
A) {}
B) dict()
C) Both A and B
D) None of the above
View AnswerC
84. What will be the output of print(“Hello, {name}”.format(name=”World”))?
A) Hello, World
B) Hello, {name}
C) Hello, name
D) Error
View AnswerA
85. What is the correct way to write an if statement in Python?
A) if x > 10:
B) if (x > 10)
C) if x > 10 then:
D) if: x > 10
View AnswerA
86. How do you check if a string contains a substring in Python?
A) substring in string
B) string.contains(substring)
C) substring.exists(string)
D) None of the above
View AnswerA
87. What is the output of print(1 + 2 * 3)?
A) 9
B) 7
C) 6
D) 5
View AnswerB
88. How do you define a private variable in a class?
A) _variable
B) variable
C) __variable
D) Both A and C
View AnswerD
89. What does the repr method return?
A) A string representation of an object
B) A human-readable string
C) A numerical value
D) None of the above
View AnswerA
90. How can you remove an item from a set in Python?
A) remove()
B) discard()
C) Both A and B
D) pop()
View AnswerC
91. What is the output of print(“abc”.find(“b”))?
A) 0
B) 1
C) -1
D) Error
View AnswerB
92. Which keyword is used to inherit a class in Python?
A) inherit
B) extends
C) class
D) is
View AnswerC
93. What is the result of print(3 == 3.0)?
A) True
B) False
C) None
D) Error
View AnswerA
94. How do you reverse a list in Python?
A) reverse()
B) list.reverse()
C) Both A and B
D) None of the above
View AnswerC
95. What is the output of print(“Hello” * 3)?
A) HelloHelloHello
B) Hello, Hello, Hello
C) Hello 3
D) Error
View AnswerA
96. How do you convert a string to lowercase in Python?
A) lower()
B) tolower()
C) lowercase()
D) None of the above
View AnswerA
97. Which of the following methods returns the first index of a substring in a string?
A) find()
B) index()
C) Both A and B
D) None of the above
View AnswerC
98. What does the keyword ‘with’ do in Python?
A) Creates a loop
B) Handles file operations
C) Defines a function
D) Initializes a variable
View AnswerB
105. What will be the output of the following code? print(type(5))
A) <class ‘int’>
B) <class ‘str’>
C) <class ‘float’>
D) <class ‘list’>
View AnswerA
100. What is the output of print([1, 2, 3].pop())?
A) 1
B) 2
C) 3
D) Error
View AnswerC