Python Programming - MCQ Practice Questions
Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.
119 questions | 100% Free
Consider the code: with open('file.txt') as f: data = f.read(). What happens when the block exits?
What will be the output of: print({x: x**2 for x in range(3)})?
Consider: class A: x = 5. What is A.x and how can it be modified?
What is the output of: print(type(lambda x: x))?
Which of the following is NOT a valid Python variable name?
What is the output of: print(10 // 3 + 10 % 3)?
What will be the data type of x after executing: x = ?
Consider the code: x = [1, 2, 3]; y = x; y.append(4). What is x?
What is the output of: print(len('Python'))?
What will be printed: print(3 2 2)?
Consider: a = 'Hello'; b = 'Hello'. Are a and b the same object?
Consider the code: def func(x, y=5): return x + y. What is func(3)?
What will be the output of: print(10 if 5 > 3 else 20)?
Consider: x = [1, 2, 3, 4, 5]; y = x[1:4]. What is y?
What is the output of: print('a' in 'banana')?
Consider: d = {'a': 1, 'b': 2}; d['c'] = 3. What is d?
What will be the output of: x = 5; x += 3; print(x)?
Consider the code: x = (1, 2, 3); x[0] = 5. What happens?
What is the output of: print(None == False)?
Consider the following code snippet: python x = [1, 2, 3] y = x y.append(4) print(x) What will be the output?