-
Which of the following is NOT a Python data type?
a) List
b) Dictionary
c) Array
d) Tuple
-
What is the output of print(3 * "Python ")?
a) Python Python Python
b) 3Python
c) PythonPythonPython
d) Python Python Python
-
Which statement correctly opens a file named "data.txt" for writing?
a) file = open("data.txt", "r")
b) file = open("data.txt", "w")
c) file = open("data.txt", "a")
d) file = open("data.txt")
-
What is the correct way to create a function in Python?
a) function myFunc():
b) def myFunc():
c) create myFunc():
d) new myFunc():
-
Which of these is NOT a valid variable name in Python?
a) my_var
b) _myVar
c) 1var
d) myVar2
-
What does the len() function return when used on a dictionary?
a) The number of key-value pairs
b) The number of keys
c) The number of values
d) The memory size of the dictionary
-
Which statement correctly imports only the sqrt function from the math module?
a) import math.sqrt
b) from math import sqrt
c) import sqrt from math
d) include math.sqrt
-
What is the result of 5 // 2 in Python?
a) 2.5
b) 2
c) 2.0
d) 3
-
Which Python data structure is ordered, mutable, and allows duplicate elements?
a) List
b) Tuple
c) Set
d) Dictionary
-
What does the range(1, 10, 2) function return?
a) [1, 3, 5, 7, 9]
b) [1, 2, 3, 4, 5, 6, 7, 8, 9]
c) [1, 3, 5, 7]
d) A range object representing numbers 1, 3, 5, 7, 9
-
Which symbol is used for single-line comments in Python?
a) //
b) #
c) /* */
d) --
-
What is the purpose of __init__ in a Python class?
a) To initialize the class
b) To import modules
c) To create a constructor
d) To end the class definition
-
What is the output of print(bool(0))?
a) 0
b) 1
c) True
d) False
-
What will list1 = [1, 2, 3]; list2 = list1; list1[0] = 5 result in for list2?
a) [1, 2, 3]
b) [5, 2, 3]
c) [5]
d) Error
-
What is the correct way to check if a key exists in a dictionary?
a) if key in dict:
b) if key exists in dict:
c) if dict.haskey(key):
d) if dict.contains(key):
-
Which statement is used to terminate a loop prematurely?
a) stop
b) break
c) exit
d) return
-
What does the strip() method do to a string?
a) Removes leading and trailing whitespace
b) Converts all characters to lowercase
c) Removes all whitespace
d) Splits the string into a list
-
What is the correct way to catch multiple exceptions in Python?
a) try: ... except Exception1, Exception2:
b) try: ... except (Exception1, Exception2):
c) try: ... catch (Exception1, Exception2):
d) try: ... except Exception1 and Exception2:
-
What is the output of ", ".join(["a", "b", "c"])?
a) "a, b, c"
b) ["a", "b", "c"]
c) "abc"
d) None of the above
-
Which data structure would be most efficient for checking if an element exists?
a) List
b) Set
c) Tuple
d) String
-
Explain the difference between append() and extend() methods in Python lists.
-
What is a decorator in Python and how is it used?
-
Describe the difference between == and is operators.
-
Explain what list comprehensions are and provide a simple example.
-
What is the purpose of virtual environments in Python?
-
Describe the difference between mutable and immutable objects in Python. Provide examples of each.
-
What are lambda functions? Provide a simple example.
-
Explain the purpose of the __str__ and __repr__ methods in a class.
-
What is the Global Interpreter Lock (GIL) in Python and how does it affect multithreading?
-
Describe the purpose and usage of the *args and **kwargs parameters in function definitions.