TRE 4 based Python Practice set 1
Que: (1). Who developed the Python programming language?
Que: (2). Which of the following is the correct extension of a Python file?
Que: (3). What will be the output of the following Python program?
a = 10
b = 3
print(a / b)
Que: (4). What will be the output of the following Python program?
print(17 // 5)
Que: (5). What will be the output of the following Python program?
print(17 % 5)
Que: (6). Which of the following data types is immutable in Python?
Que: (7). What will be the output of the following Python program?
numbers = [10, 20, 30, 40]
print(numbers[-1])
Que: (8). What will be the output of the following Python program?
a = [1, 2, 3, 4, 5]
print(a[1:4])
Que: (9). Which method is used to add an element at the end of a Python list?
Que: (10). What will be the output of the following Python program?
print(list(range(1, 6, 2)))
Que: (11). Which keyword is used to define a function in Python?
Que: (12). What will be the output of the following Python program?
s = "COMPUTER"
print(s[1:4])
Que: (13). Which of the following is used to create a dictionary in Python?
Que: (14). What will be the output of the following Python program?
a = {1, 2, 2, 3, 3, 4}
print(len(a))
Que: (15). Which operator is used for exponentiation in Python?
Que: (16). What will be the output of the following Python program?
print(10 > 5 and 5 < 2)
Que: (17). Which statement is used to terminate a loop immediately in Python?
Que: (18). What will be the output of the following Python program?
for i in range(3):
print(i, end=" ")
Que: (19). Which keyword is used to handle exceptions in Python?
Que: (20). What will be the output of the following Python program?
x = 10
print(type(x).__name__)
Que: (21). Which of the following inheritance types is directly supported by Python?
Que: (22). What will be the output of the following Python program?
def add_item(x, items=[]):
items.append(x)
return items
print(add_item(1))
print(add_item(2))
Que: (23). Which special method is automatically called when a new object is initialized in a Python class?
Que: (24). What will be the output of the following Python program?
x = 10
def test():
x = 20
test()
print(x)
Que: (25). Which keyword is used to modify a variable from an enclosing function scope in Python?
Que: (26). What will be the output of the following Python program?
a = [1, 2, 3]
b = a
c = [1, 2, 3]
print(a is b, a is c)
Que: (27). Which module is commonly used to create abstract base classes in Python?
Que: (28). What happens when an attempt is made to instantiate an abstract class containing an unimplemented abstract method?
Que: (29). What will be the output of the following Python program?
class A:
pass
class B(A):
pass
class C(A):
pass
class D(B, C):
pass
print([x.__name__ for x in D.mro()])
Que: (30). Which decorator is used to define a class method in Python?
Que: (31). What will be the output of the following Python program?
def numbers():
yield 10
yield 20
x = numbers()
print(next(x))
print(next(x))
Que: (32). Which of the following statements about Python generators is correct?
Que: (33). What will be the output of the following Python program?
def decorator(func):
def wrapper():
return "Hello " + func()
return wrapper
@decorator
def message():
return "Python"
print(message())
Que: (34). What will be the output of the following Python program?
try:
print("A")
finally:
print("B")
Que: (35). Which file opening mode creates a new file but raises an error if the file already exists?
Que: (36). What is the main purpose of the with statement when working with files in Python?
Que: (37). What will be the output of the following Python program?
import copy
a = [[1, 2], [3, 4]]
b = copy.copy(a)
b[0][0] = 99
print(a[0][0])
Que: (38). Which of the following statements about Python memory management is correct?
Que: (39). What will be the output of the following Python program?
functions = [lambda: i for i in range(3)]
print([f() for f in functions])
Que: (40). What is the correct statement about the __del__() method in Python?
Que: (41). Which feature of Python makes it suitable for structured programming?
Que: (42). Which language is primarily used to define the structure and content of web pages displayed by a browser?
Que: (43). Which of the following statements is correct about the execution of Python programs?
Que: (44). Which of the following is NOT a valid Python identifier?
Que: (45). What error occurs when a colon is omitted after an if statement in Python?
if x > 10
print("Greater")
Que: (46). Which shortcut key is commonly used to run a Python script in IDLE?
Que: (47). Which file extension is commonly used for a compiled Python bytecode file?
Que: (48). What will happen when the following Python statement is executed?
ptr = None
del ptr
print("Success")
Que: (49). Which of the following correctly creates a list containing ten zeros in Python?
Que: (50). What will be the output of the following Python program?
s1 = "Hello"
s2 = "World"
s3 = s1 + " " + s2
print(s3)
Que: (51). What is the default accessibility of attributes in a Python class?
Que: (52). What happens when a file is opened using the w mode in Python?
Que: (53). Which of the following statements about Python file opening modes is correct? I. r is used for reading. II. w is used for writing and truncating. III. a is used for appending.
Que: (54). Which of the following is a correct Python function definition using type annotations?
Que: (55). What will be the output of the following Python program?
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
print(factorial(5))
Que: (56). Which of the following is the correct syntax for inheritance in Python?
Que: (57). Which built-in function is used to check whether an object belongs to a particular class or its subclass?
Que: (58). Which of the following statements correctly describes the relationship between a class and an object in Python?
Que: (59). Which of the following features of Python allows the same operation to behave differently for different object types?
Que: (60). Which OOP features are demonstrated by the following Python code?
class Student:
def __init__(self, marks):
self.__marks = marks
class Topper(Student):
pass
Que: (61). What will be the output of len("BPSC") in Python?
print(len("BPSC"))
Que: (62). Which string method converts all characters into lowercase?
Que: (63). What will be the output of the following Python statement?
print("banana".find("na"))
Que: (64). What will be the output of the following Python statement?
print("red blue green".split())
Que: (65). What will be the output of the following list comprehension?
print([x*x for x in range(1, 4)])
Que: (66). Which is the correct syntax for creating a tuple containing only one element?
Que: (67). What will be the values of a and b after executing the following statement?
a, b = (10, 20)
print(a, b)
Que: (68). What does get() return when a dictionary key is missing and no default value is supplied?
Que: (69). Which method returns a view containing all keys of a Python dictionary?
Que: (70). What will be the output of the following Python program?
data = {"a": 10, "b": 20}
print(data.pop("a"))
Que: (71). Which operator checks whether an element exists in a sequence?
Que: (72). What will be the output of the following Python expression?
print(5 & 3)
Que: (73). What will be the result of the following Python expression?
print(2 + 3 * 4)
Que: (74). What will be the output of the following Python expression?
print(-7 // 2)
Que: (75). Which is the correct syntax of a conditional expression in Python?
Que: (76). How many times will print execute in the following program?
for i in range(2):
for j in range(3):
print(i, j)
Que: (77). What will be the output of the following Python statement?
print(list(range(5, 0, -2)))
Que: (78). What will be the output of the following Python program?
import math
print(math.ceil(4.2))
Que: (79). What will be the output of the following Python statement?
print(ord("A"))
Que: (80). What will be the output of the following Python statement?
print(list(enumerate(["A", "B"])))