TRE 4 based Python Practice set 1

Que: (1). Who developed the Python programming language?

A.
C.
B.
D.
E.
Open question page

Que: (2). Which of the following is the correct extension of a Python file?

B.
A.
C.
D.
E.
Open question page

Que: (3). What will be the output of the following Python program?

                            a = 10
b = 3
print(a / b)
                        
B.
A.
C.
D.
E.
Open question page

Que: (4). What will be the output of the following Python program?

                            print(17 // 5)
                        
B.
C.
A.
D.
E.
Open question page

Que: (5). What will be the output of the following Python program?

                            print(17 % 5)
                        
C.
A.
B.
D.
E.
Open question page

Que: (6). Which of the following data types is immutable in Python?

B.
A.
C.
D.
E.
Open question page

Que: (7). What will be the output of the following Python program?

                            numbers = [10, 20, 30, 40]
print(numbers[-1])
                        
B.
C.
A.
D.
E.
Open question page

Que: (8). What will be the output of the following Python program?

                            a = [1, 2, 3, 4, 5]
print(a[1:4])
                        
C.
B.
A.
D.
E.
Open question page

Que: (9). Which method is used to add an element at the end of a Python list?

A.
B.
C.
D.
E.
Open question page

Que: (10). What will be the output of the following Python program?

                            print(list(range(1, 6, 2)))
                        
B.
A.
C.
D.
E.
Open question page

Que: (11). Which keyword is used to define a function in Python?

C.
B.
A.
D.
E.
Open question page

Que: (12). What will be the output of the following Python program?

                            s = "COMPUTER"
print(s[1:4])
                        
C.
B.
A.
D.
E.
Open question page

Que: (13). Which of the following is used to create a dictionary in Python?

A.
B.
C.
D.
E.
Open question page

Que: (14). What will be the output of the following Python program?

                            a = {1, 2, 2, 3, 3, 4}
print(len(a))
                        
A.
C.
B.
D.
E.
Open question page

Que: (15). Which operator is used for exponentiation in Python?

C.
B.
A.
D.
E.
Open question page

Que: (16). What will be the output of the following Python program?

                            print(10 > 5 and 5 < 2)
                        
A.
C.
B.
D.
E.
Open question page

Que: (17). Which statement is used to terminate a loop immediately in Python?

C.
A.
B.
D.
E.
Open question page

Que: (18). What will be the output of the following Python program?

                            for i in range(3):
    print(i, end=" ")
                        
B.
C.
A.
D.
E.
Open question page

Que: (19). Which keyword is used to handle exceptions in Python?

B.
C.
A.
D.
E.
Open question page

Que: (20). What will be the output of the following Python program?

                            x = 10
print(type(x).__name__)
                        
A.
B.
C.
D.
E.
Open question page

Que: (21). Which of the following inheritance types is directly supported by Python?

C.
B.
A.
D.
E.
Open question page

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))
                        
B.
C.
A.
D.
E.
Open question page

Que: (23). Which special method is automatically called when a new object is initialized in a Python class?

B.
A.
C.
D.
E.
Open question page

Que: (24). What will be the output of the following Python program?

                            x = 10

def test():
    x = 20

test()
print(x)
                        
C.
B.
A.
D.
E.
Open question page

Que: (25). Which keyword is used to modify a variable from an enclosing function scope in Python?

B.
C.
A.
D.
E.
Open question page

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)
                        
A.
B.
C.
D.
E.
Open question page

Que: (27). Which module is commonly used to create abstract base classes in Python?

B.
A.
C.
D.
E.
Open question page

Que: (28). What happens when an attempt is made to instantiate an abstract class containing an unimplemented abstract method?

B.
A.
C.
D.
E.
Open question page

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()])
                        
B.
A.
C.
D.
E.
Open question page

Que: (30). Which decorator is used to define a class method in Python?

A.
B.
C.
D.
E.
Open question page

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))
                        
A.
B.
C.
D.
E.
Open question page

Que: (32). Which of the following statements about Python generators is correct?

A.
C.
B.
D.
E.
Open question page

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())
                        
B.
A.
C.
D.
E.
Open question page

Que: (34). What will be the output of the following Python program?

                            try:
    print("A")
finally:
    print("B")
                        
C.
A.
B.
D.
E.
Open question page

Que: (35). Which file opening mode creates a new file but raises an error if the file already exists?

C.
B.
A.
D.
E.
Open question page

Que: (36). What is the main purpose of the with statement when working with files in Python?

A.
C.
B.
D.
E.
Open question page

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])
                        
A.
B.
C.
D.
E.
Open question page

Que: (38). Which of the following statements about Python memory management is correct?

B.
C.
A.
D.
E.
Open question page

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])
                        
C.
A.
B.
D.
E.
Open question page

Que: (40). What is the correct statement about the __del__() method in Python?

A.
B.
C.
D.
E.
Open question page

Que: (41). Which feature of Python makes it suitable for structured programming?

B.
C.
A.
D.
E.
Open question page

Que: (42). Which language is primarily used to define the structure and content of web pages displayed by a browser?

B.
C.
A.
D.
E.
Open question page

Que: (43). Which of the following statements is correct about the execution of Python programs?

C.
B.
A.
D.
E.
Open question page

Que: (44). Which of the following is NOT a valid Python identifier?

C.
B.
A.
D.
E.
Open question page

Que: (45). What error occurs when a colon is omitted after an if statement in Python?

                            if x > 10
    print("Greater")
                        
C.
B.
A.
D.
E.
Open question page

Que: (46). Which shortcut key is commonly used to run a Python script in IDLE?

C.
A.
B.
D.
E.
Open question page

Que: (47). Which file extension is commonly used for a compiled Python bytecode file?

B.
C.
A.
D.
E.
Open question page

Que: (48). What will happen when the following Python statement is executed?

                            ptr = None
del ptr
print("Success")
                        
C.
B.
A.
D.
E.
Open question page

Que: (49). Which of the following correctly creates a list containing ten zeros in Python?

C.
A.
B.
D.
E.
Open question page

Que: (50). What will be the output of the following Python program?

                            s1 = "Hello"
s2 = "World"
s3 = s1 + " " + s2
print(s3)
                        
B.
A.
C.
D.
E.
Open question page

Que: (51). What is the default accessibility of attributes in a Python class?

A.
C.
B.
D.
E.
Open question page

Que: (52). What happens when a file is opened using the w mode in Python?

C.
A.
B.
D.
E.
Open question page

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.

B.
A.
C.
D.
E.
Open question page

Que: (54). Which of the following is a correct Python function definition using type annotations?

B.
A.
C.
D.
E.
Open question page

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))
                        
B.
C.
A.
D.
E.
Open question page

Que: (56). Which of the following is the correct syntax for inheritance in Python?

C.
B.
A.
D.
E.
Open question page

Que: (57). Which built-in function is used to check whether an object belongs to a particular class or its subclass?

B.
C.
A.
D.
E.
Open question page

Que: (58). Which of the following statements correctly describes the relationship between a class and an object in Python?

A.
B.
C.
D.
E.
Open question page

Que: (59). Which of the following features of Python allows the same operation to behave differently for different object types?

C.
A.
B.
D.
E.
Open question page

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
                        
B.
C.
A.
D.
E.
Open question page

Que: (61). What will be the output of len("BPSC") in Python?

                            print(len("BPSC"))
                        
B.
C.
A.
D.
E.
Open question page

Que: (62). Which string method converts all characters into lowercase?

B.
A.
C.
D.
E.
Open question page

Que: (63). What will be the output of the following Python statement?

                            print("banana".find("na"))
                        
C.
B.
A.
D.
E.
Open question page

Que: (64). What will be the output of the following Python statement?

                            print("red blue green".split())
                        
C.
A.
B.
D.
E.
Open question page

Que: (65). What will be the output of the following list comprehension?

                            print([x*x for x in range(1, 4)])
                        
C.
B.
A.
D.
E.
Open question page

Que: (66). Which is the correct syntax for creating a tuple containing only one element?

C.
A.
B.
D.
E.
Open question page

Que: (67). What will be the values of a and b after executing the following statement?

                            a, b = (10, 20)
print(a, b)
                        
C.
A.
B.
D.
E.
Open question page

Que: (68). What does get() return when a dictionary key is missing and no default value is supplied?

B.
C.
A.
D.
E.
Open question page

Que: (69). Which method returns a view containing all keys of a Python dictionary?

A.
C.
B.
D.
E.
Open question page

Que: (70). What will be the output of the following Python program?

                            data = {"a": 10, "b": 20}
print(data.pop("a"))
                        
B.
C.
A.
D.
E.
Open question page

Que: (71). Which operator checks whether an element exists in a sequence?

A.
B.
C.
D.
E.
Open question page

Que: (72). What will be the output of the following Python expression?

                            print(5 & 3)
                        
A.
B.
C.
D.
E.
Open question page

Que: (73). What will be the result of the following Python expression?

                            print(2 + 3 * 4)
                        
A.
C.
B.
D.
E.
Open question page

Que: (74). What will be the output of the following Python expression?

                            print(-7 // 2)
                        
B.
A.
C.
D.
E.
Open question page

Que: (75). Which is the correct syntax of a conditional expression in Python?

B.
C.
A.
D.
E.
Open question page

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)
                        
A.
B.
C.
D.
E.
Open question page

Que: (77). What will be the output of the following Python statement?

                            print(list(range(5, 0, -2)))
                        
A.
C.
B.
D.
E.
Open question page

Que: (78). What will be the output of the following Python program?

                            import math
print(math.ceil(4.2))
                        
C.
B.
A.
D.
E.
Open question page

Que: (79). What will be the output of the following Python statement?

                            print(ord("A"))
                        
A.
B.
C.
D.
E.
Open question page

Que: (80). What will be the output of the following Python statement?

                            print(list(enumerate(["A", "B"])))
                        
A.
C.
B.
D.
E.
Open question page