Python Programming: Toughest Quiz!

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Vaibhav99aggarwa
V
Vaibhav99aggarwa
Community Contributor
Quizzes Created: 1 | Total Attempts: 1,112
| Attempts: 1,112
SettingsSettings
Please wait...
  • 1/60 Questions

    Suppose list1 is [2445,133,12454,123], what is max(list1)?

    • 2445
    • 133
    • 12454
    • 123
Please wait...
About This Quiz

Dive into the 'Python Programming: Toughest Quiz!' to challenge and enhance your Python skills. This quiz tests your knowledge on Python keywords, operators, data types, and code outputs, making it ideal for advanced learners looking to test their expertise.

Python Programming: Toughest Quiz! - Quiz

Quiz Preview

  • 2. 

    Which one do you like?What will be the output of the following Python code? ⦁    >>>example = "snow world" ⦁    >>>print("%s" % example[4:7])

    • Wo

    • World

    • Sn

    • Rl

    Correct Answer
    A. Wo
    Explanation
    The code is using string slicing to extract a portion of the string "example". The slicing syntax [4:7] means to start at index 4 and go up to, but not including, index 7. In the string "snow world", the characters at indexes 4, 5, and 6 are "w", "o", and " ", respectively. So, the output will be "wo".

    Rate this question:

  • 3. 

    What will be the output of the following Python code? ⦁    def printMax(a, b): ⦁        if a > b: ⦁            print(a, 'is maximum') ⦁        elif a == b: ⦁            print(a, 'is equal to', b) ⦁        else: ⦁            print(b, 'is maximum') ⦁    printMax(3, 4)

    •  3

    • 4

    • 4 is maximum

    • None of the mentioned

    Correct Answer
    A. 4 is maximum
    Explanation
    The given Python code defines a function called `printMax` that takes two parameters `a` and `b`. The code then compares the values of `a` and `b` using conditional statements. If `a` is greater than `b`, it prints `a` followed by "is maximum". If `a` is equal to `b`, it prints `a` followed by "is equal to" followed by `b`. If neither of these conditions is true, it means that `b` is greater than `a`, so it prints `b` followed by "is maximum".

    In the given code, `printMax(3, 4)` is called, so `a` is 3 and `b` is 4. Since `b` is greater than `a`, the output will be "4 is maximum".

    Rate this question:

  • 4. 

    What will be the output of the following Python Code?     1.>>>str=”hello”     2.>>>str[:2]

    • He

    • Lo

    • Olleh

    • Hello

    Correct Answer
    A. He
    Explanation
    The given Python code initializes a variable "str" with the value "hello". The expression "str[:2]" is used to extract the substring from index 0 to index 1 (excluding index 2) from the string. Therefore, the output will be "he".

    Rate this question:

  • 5. 

    Which keyword is used for function?

    • Fun

    • Define

    • Def

    • Function

    Correct Answer
    A. Def
    Explanation
    The keyword "def" is used for defining a function in programming languages like Python. It is followed by the name of the function and a set of parentheses, which may contain parameters. The "def" keyword signifies the start of a function definition and is essential for creating reusable blocks of code that can be called and executed multiple times within a program.

    Rate this question:

  • 6. 

    Suppose listExample is [3, 4, 5, 20, 5, 25, 1, 3], what is list1 after listExample.pop(1)?

    • [3, 4, 5, 20, 5, 25, 1, 3]

    • [1, 3, 3, 4, 5, 5, 20, 25]

    • [3, 5, 20, 5, 25, 1, 3]

    • [1, 3, 4, 5, 20, 5, 25]

    Correct Answer
    A. [3, 5, 20, 5, 25, 1, 3]
    Explanation
    After executing the code listExample.pop(1), the element at index 1 in listExample is removed. Therefore, the resulting list1 will be [3, 5, 20, 5, 25, 1, 3].

    Rate this question:

  • 7. 

    Which of the following expressions is an example of type conversion?

    • 4.0+float(3)

    • 5.3+6.3

    • 5.0+3

    • 3+7

    Correct Answer
    A. 4.0+float(3)
    Explanation
    The expression "4.0+float(3)" is an example of type conversion because it involves converting the integer value 3 into a float value using the "float()" function. This allows for the addition of a float value (4.0) with the converted float value (3.0), resulting in a float value as the final result. Type conversion is the process of changing the data type of a value to perform operations or assignments that require a different data type.

    Rate this question:

  • 8. 

    Which of these is not a core data type?

    • Lists

    • Dictionaries

    • Tuples

    • Classes

    Correct Answer
    A. Classes
    Explanation
    Classes are not considered a core data type in Python. Core data types in Python include lists, dictionaries, and tuples. Classes are used to create custom objects and define their properties and behaviors. They are used for object-oriented programming and are not considered as fundamental data types in Python.

    Rate this question:

  • 9. 

    What datatype is the object below? L=[1, 23, “Hello” , 2]

    • List

    • Dictionary

    • Tuple

    • Array

    Correct Answer
    A. List
    Explanation
    The object L is a list because it is enclosed in square brackets and contains a sequence of elements separated by commas. Lists are a datatype in Python that can hold different types of elements, such as integers, strings, and other objects. In this case, the list L contains the elements 1, 23, "Hello", and 2.

    Rate this question:

  • 10. 

    Which of the following is a Python tuple?

    • [1, 2, 3]

    • (1, 2, 3)

    • {1, 2, 3}

    • {}

    Correct Answer
    A. (1, 2, 3)
    Explanation
    The correct answer is (1, 2, 3) because a tuple in Python is defined by enclosing elements in parentheses. This distinguishes it from a list (option [1, 2, 3]) which uses square brackets, a set (option {1, 2, 3}) which uses curly braces, and an empty dictionary (option {}).

    Rate this question:

  • 11. 

    What will be the output of the following Python code? if (9 < 0) and (0 < -9):     print("hello") elif (9 > 0) or False:     print("good") else:     print("bad")

    • Error

    • Hello

    • Good

    • Bad

    Correct Answer
    A. Good
    Explanation
    The output of the code will be "good" because the condition in the elif statement is true. In the if statement, the first condition (9 < 0) is false, so it is not executed. The second condition (0 < -9) is also false, so the code inside the if statement is not executed. In the elif statement, the first condition (9 > 0) is true, so the code inside the elif statement is executed, resulting in the output "good".

    Rate this question:

  • 12. 

    Which data type use key-value pair?

    • List

    • Dictionary

    • Array

    • Tuple

    Correct Answer
    A. Dictionary
    Explanation
    A dictionary is a data type that uses key-value pairs. It allows you to store and retrieve values based on a unique key. Each key is associated with a value, and you can use the key to access the corresponding value. This makes dictionaries useful for organizing and accessing data in a structured way. Unlike lists, arrays, and tuples, dictionaries provide a way to store data in a non-sequential manner, making them ideal for tasks such as mapping and indexing.

    Rate this question:

  • 13. 

    Which one of these is floor division?

    • /

    • //

    • %

    • None of the above

    Correct Answer
    A. //
    Explanation
    The double forward slash operator "//" represents floor division. Floor division returns the largest integer that is less than or equal to the result of the division. It discards the decimal part of the quotient and gives the whole number result.

    Rate this question:

  • 14. 

     What is Instantiation in terms of OOP terminology?

    •  Deleting an instance of class

    •  Modifying an instance of class

    • Copying an instance of class

    • Creating an instance of class

    Correct Answer
    A. Creating an instance of class
    Explanation
    Instantiation in terms of OOP terminology refers to the process of creating an instance of a class. In object-oriented programming, a class is a blueprint for creating objects, and an instance is an object created based on that blueprint. When we instantiate a class, we create a new object of that class, allocating memory for it and initializing its attributes and methods. This allows us to use the functionalities and properties defined in the class blueprint to perform specific tasks or operations. Therefore, the correct answer is "Creating an instance of class."

    Rate this question:

  • 15. 

    The readlines() method returns ____________

    • Str

    • A list of lines

    •  a list of single characters

    • A list of integers

    Correct Answer
    A. A list of lines
    Explanation
    The readlines() method is used to read all the lines from a file and returns them as a list of lines. Each line is represented as a string element in the list. Therefore, the correct answer is "a list of lines."

    Rate this question:

  • 16. 

     What does single-level inheritance mean?

    • A subclass derives from a class which in turn derives from another class

    • A single superclass inherits from multiple subclasses

    • A single subclass derives from a single superclass

    • Multiple base classes inherit a single derived class

    Correct Answer
    A. A single subclass derives from a single superclass
    Explanation
    Single-level inheritance refers to the concept where a subclass is derived from a single superclass. In this type of inheritance, there is a one-to-one relationship between the subclass and superclass, meaning that a subclass can only inherit properties and methods from a single superclass. This allows for the creation of a hierarchical structure where each subclass inherits the characteristics of its immediate superclass, which in turn may inherit from another superclass. It provides a way to organize and structure code by promoting code reuse and maintaining a clear hierarchy of classes.

    Rate this question:

  • 17. 

    Python supports the creation of anonymous functions at runtime, using a construct called __________

    • Lambda

    • Pi

    • Anonymous

    • None of the mentioned

    Correct Answer
    A. Lambda
    Explanation
    Python supports the creation of anonymous functions at runtime using a construct called "lambda". Lambda functions are small, one-line functions that do not have a name and are defined using the keyword "lambda". They are commonly used when a small function is needed for a short period of time and it is not necessary to define a separate function.

    Rate this question:

  • 18. 

    Which of these definitions correctly describes a module?

    •  Denoted by triple quotes for providing the specification of certain program elements

    • Design and implementation of specific functionality to be incorporated into a program

    • Defines the specification of how it is to be used

    • Any program that reuses code

    Correct Answer
    A. Design and implementation of specific functionality to be incorporated into a program
    Explanation
    A module is a unit of code that is designed and implemented to provide specific functionality that can be incorporated into a program. It is not just a specification or a way of using code, but rather the actual implementation of a specific functionality that can be reused in different programs.

    Rate this question:

  • 19. 

    What will be the output of the following Python code? class test:      def __init__(self,a="Hello World"):          self.a=a        def display(self):          print(self.a) obj=test() obj.display()

    •  The program has an error because constructor can’t have default arguments

    • Nothing is displayed

    • “Hello World” is displayed

    • The program has an error display function doesn’t have parameters

    Correct Answer
    A. “Hello World” is displayed
    Explanation
    The code defines a class called "test" with a constructor that takes a default argument of "Hello World". The constructor initializes an instance variable "a" with the value passed as an argument or the default value.

    The code then defines a method called "display" which prints the value of "a".

    An object of the "test" class is created and its "display" method is called. Since the object was created without passing any argument, the default value "Hello World" is assigned to "a". Therefore, when the "display" method is called, it prints "Hello World".

    Rate this question:

  • 20. 

    Operators with the same precedence are evaluated in which manner:

    • Left to Right

    • Right to Left

    • Can't say

    • None of the above

    Correct Answer
    A. Left to Right
    Explanation
    Operators with the same precedence are evaluated from left to right. This means that when there are multiple operators with the same precedence in an expression, the evaluation starts from the leftmost operator and moves towards the right. The order of evaluation is determined by the position of the operators in the expression, with the leftmost operator being evaluated first and the rightmost operator being evaluated last.

    Rate this question:

  • 21. 

     Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation?

    • Print(list1[0])

    • Print(list1[:2])

    • Print(list1[:-2])

    • All of the mentioned

    Correct Answer
    A. All of the mentioned
    Explanation
    All of the mentioned options are correct syntax for slicing operation. The first option, `print(list1[0])`, will print the element at index 0 of the list, which is 4. The second option, `print(list1[:2])`, will print the elements from the start of the list up to index 2 (exclusive), which are [4, 2]. The third option, `print(list1[:-2])`, will print all the elements of the list except the last two, which are [4, 2, 2, 4, 5, 2]. Therefore, all of the mentioned options are correct.

    Rate this question:

  • 22. 

    What will be the output of the following Python code? i = 1 while True:     if i%2 == 0:         break     print(i)     i += 2

    • 1

    • 1 2

    • 1 2 3 4 5 6 

    • 1 3 5 7 9 11

    Correct Answer
    A. 1 3 5 7 9 11
    Explanation
    The given code starts with i=1 and enters an infinite loop. Inside the loop, it checks if i is divisible by 2. Since 1 is not divisible by 2, the condition is false and the break statement is not executed. Therefore, the code continues to print the value of i, which is 1, and then increments i by 2. This process repeats indefinitely, printing odd numbers in ascending order: 1, 3, 5, 7, 9, 11.

    Rate this question:

  • 23. 

    What will be the output of the following Python code snippet? 1. d={“john”:40 , “peter”:45} 2. print(list(d.keys()))

    • [“john”, “peter”]

    • [“john”:40, “peter”:45]

    • (“john”, “peter”)

    • (“john”:40, “peter”:45)

    Correct Answer
    A. [“john”, “peter”]
    Explanation
    The code snippet creates a dictionary "d" with keys "john" and "peter" and their corresponding values. The "print(list(d.keys()))" statement prints the list of keys in the dictionary, which is ["john", "peter"].

    Rate this question:

  • 24. 

     What will be the output of the following Python expression? round(4.5676,2)?

    • 4.5

    • 4.6

    • 4.57

    • 4.56

    Correct Answer
    A. 4.57
    Explanation
    The round() function in Python is used to round a number to a specified number of decimal places. In this case, the expression round(4.5676, 2) will round the number 4.5676 to 2 decimal places. The result of this expression will be 4.57.

    Rate this question:

  • 25. 

    The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same.

    • True

    • False

    • Can't say

    Correct Answer
    A. True
    Explanation
    The expression 4/(3*(2-1)) simplifies to 4/(3*1), which further simplifies to 4/3. On the other hand, the expression 4/3*(2-1) simplifies to 4/3*1, which is also equal to 4/3. Therefore, both expressions result in the same value, making the statement true.

    Rate this question:

  • 26. 

    What will be the output of the following Python code? class Truth:     pass x=Truth() bool(x)

    • Pass

    • True

    • False

    • Error

    Correct Answer
    A. True
    Explanation
    The code defines a class called "Truth" but does not have any methods or attributes. It then creates an instance of the class called "x". The bool() function is used to check the truthiness of the object "x". Since "x" is an instance of a class, it is considered truthy, so the output of the code will be True.

    Rate this question:

  • 27. 

    What will be the output of the following Python code? ⦁    class father: ⦁        def __init__(self, param): ⦁            self.o1 = param ⦁      ⦁    class child(father): ⦁        def __init__(self, param): ⦁            self.o2 = param ⦁      ⦁    >>>obj = child(22) ⦁    >>>print "%d %d" % (obj.o1, obj.o2)

    • None None

    • None 22

    • 22 None

    • Error is generated

    Correct Answer
    A. Error is generated
    Explanation
    The code will generate an error because the child class does not have a constructor that calls the constructor of the parent class. Therefore, when the child object is created and the print statement tries to access the attributes o1 and o2, they are not defined, resulting in an error.

    Rate this question:

  • 28. 

     What will be the output of the following Python code? >>> a={"a":1,"b":2,"c":3} >>> b=dict(zip(a.values(),a.keys())) >>> b

    • {‘a’: 1, ‘b’: 2, ‘c’: 3}

    • An exception is thrown

    • {‘a’: ‘b’: ‘c’: }

    • {1: ‘a’, 2: ‘b’, 3: ‘c’}

    Correct Answer
    A. {1: ‘a’, 2: ‘b’, 3: ‘c’}
    Explanation
    The given Python code first creates a dictionary 'a' with keys 'a', 'b', and 'c' and corresponding values 1, 2, and 3. Then, it creates a new dictionary 'b' by swapping the keys and values of dictionary 'a' using the zip() function. The zip() function takes the values of dictionary 'a' as keys and the keys of dictionary 'a' as values, and creates a list of tuples. The dict() function then converts this list of tuples into a dictionary. Therefore, the output of the code will be a dictionary with keys 1, 2, and 3 and corresponding values 'a', 'b', and 'c'.

    Rate this question:

  • 29. 

    What is the return type of function id?

    • Int

    • Float

    • Bool

    • Dict

    Correct Answer
    A. Int
    Explanation
    The return type of the function "id" is "int".

    Rate this question:

  • 30. 

    What is the value of the following expression? float (22//3+3/3)

    • 8

    • 8.0

    • 8.3

    • 8.33

    Correct Answer
    A. 8.0
    Explanation
    The expression calculates the value of 22 divided by 3 using integer division (//), which results in 7. Then, it adds the result of 3 divided by 3, which is 1. Finally, it converts the result to a float using the float() function. The final result is 8.0.

    Rate this question:

  • 31. 

    What will be the output of the following Python code? ⦁    x = 50 ⦁    def func(): ⦁        global x ⦁        print('x is', x) ⦁        x = 2 ⦁        print('Changed global x to', x) ⦁    func() ⦁    print('Value of x is', x)

    • X is 50 Changed global x to 2 Value of x is 50

    • X is 50 Changed global x to 2 Value of x is 2

    • X is 50 Changed global x to 50 Value of x is 50

    • None of the mentioned

    Correct Answer
    A. X is 50 Changed global x to 2 Value of x is 2
    Explanation
    The code starts by assigning the value 50 to the variable x. Then, a function named func is defined. Inside the function, the global keyword is used to indicate that the variable x is a global variable. The function prints the value of x, which is 50 at this point. Then, the value of x is changed to 2 using the assignment statement. The function prints the message "Changed global x to 2". Finally, outside the function, the value of x is printed again, which is 2 now. Therefore, the output of the code will be "x is 50, Changed global x to 2, Value of x is 2".

    Rate this question:

  • 32. 

    What will be the output of the following Python code snippet? print('a@ 1,'.islower())

    • True

    • False

    • None

    • Error

    Correct Answer
    A. True
    Explanation
    The output of the code snippet will be True. This is because the islower() method checks if all characters in the string are lowercase, and in this case, the string "a@ 1," does not contain any uppercase characters. Therefore, the method returns True.

    Rate this question:

  • 33. 

      _____ represents an entity in the real world with its identity and behaviour.

    • A method

    • An object

    • A class

    • An operator

    Correct Answer
    A. An object
    Explanation
    An object represents an entity in the real world with its identity and behavior. Objects are instances of classes and they encapsulate data and methods. They have a unique identity and can perform actions or have actions performed on them. Objects allow for the modeling of real-world entities in a program, enabling interaction and manipulation of data and behavior associated with that entity.

    Rate this question:

  • 34. 

    Which of the following operators has its associativity from right to left?

    • +

    • //

    • %

    • **

    Correct Answer
    A. **
    Explanation
    The operator that has its associativity from right to left is the exponentiation operator (**). This means that if there are multiple occurrences of this operator in an expression, the evaluation will start from the rightmost occurrence and proceed towards the left. For example, in the expression 2 ** 3 ** 2, the evaluation will be done as 2 ** (3 ** 2), resulting in 2 ** 9 = 512.

    Rate this question:

  • 35. 

    What will be the output of the following Python code? ⦁    >>>list1 = [1, 3] ⦁    >>>list2 = list1 ⦁    >>>list1[0] = 4 ⦁    >>>print(list2)

    • [1, 3]

    • [4, 3]

    • [1, 4]

    • [1, 3, 4]

    Correct Answer
    A. [4, 3]
    Explanation
    The output of the code will be [4, 3]. This is because when we assign list1 to list2, we are actually creating a reference to the same list object. So any changes made to list1 will also be reflected in list2. When we change the value of the first element in list1 to 4, it also changes the value in list2. Therefore, the output is [4, 3].

    Rate this question:

  • 36. 

    What will be the output of the following Python code? >>> a={'B':5,'A':9,'C':7} >>> sorted(a)

    • [‘A’,’B’,’C’]

    • [‘B’,’C’,’A’]

    • [5,7,9]

    • [9,5,7]

    Correct Answer
    A. [‘A’,’B’,’C’]
    Explanation
    The code will output a sorted list of the keys in the dictionary 'a'. The keys in the dictionary are 'B', 'A', and 'C', and when sorted, they will be in alphabetical order, resulting in the output ['A', 'B', 'C'].

    Rate this question:

  • 37. 

    Which of the following is not a complex number?

    • K=2+3j

    • K=complex(2,3)

    • K=2+3l

    • K=2+3J

    Correct Answer
    A. K=2+3l
    Explanation
    The given expression k=2+3l represents a complex number because it has a real part (2) and an imaginary part (3l), where l is a variable. In complex numbers, the imaginary part is a multiple of the imaginary unit i or j. Therefore, all the other options, k=2+3j, k=2+3J, and k=2+3j, are valid complex numbers as they follow the standard notation of a complex number with the imaginary unit.

    Rate this question:

  • 38. 

    What will be the output of the following Python code? s=["pune", "mumbai", "delhi"] [(w.upper(), len(w)) for w in s]

    • Error

    • [‘PUNE’, 4, ‘MUMBAI’, 6, ‘DELHI’, 5]

    • [PUNE, 4, MUMBAI, 6, DELHI, 5]

    • [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]

    Correct Answer
    A. [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)]
    Explanation
    The given code uses a list comprehension to create a new list. It iterates over each element in the list 's', and for each element, it converts it to uppercase using the 'upper()' method and calculates the length of the string using the 'len()' function. The result is a list of tuples, where each tuple contains the uppercase string and its length. Therefore, the output will be [(‘PUNE’, 4), (‘MUMBAI’, 6), (‘DELHI’, 5)].

    Rate this question:

  • 39. 

     Suppose d = {“john”:40, “peter”:45}. To obtain the number of entries in dictionary which command do we use?

    • D.size()

    • Len(d)

    • Size(d)

    • D.len()

    Correct Answer
    A. Len(d)
    Explanation
    The len() function is used to obtain the number of entries in a dictionary. In this case, len(d) will return the number of entries in the dictionary d, which is 2.

    Rate this question:

  • 40. 

     What will be the output of the following Python code? a=10 b=20 def change():     global b     a=45     b=56 change() print(a) print(b)

    • 10 56

    • 45 56

    • 10 20

    • Syntax Error

    Correct Answer
    A. 10 56
    Explanation
    The code defines two variables, a and b, with initial values of 10 and 20 respectively. Then, a function called change is defined. Inside the function, the global keyword is used to indicate that the variable b is a global variable. The variable a is assigned a new value of 45, and the variable b is assigned a new value of 56. The change function is then called. Finally, the values of a and b are printed. Since the variable a is not declared as global inside the function, the value of a remains unchanged and is still 10. However, the variable b is declared as global, so the value of b is updated to 56. Therefore, the output of the code is 10 and 56.

    Rate this question:

  • 41. 

     What will be the output of the following Python code? class A():     def disp(self):         print("A disp()") class B(A):     pass obj = B() obj.disp()

    •  Invalid syntax for inheritance

    • Error because when object is created, argument must be passed

    • Nothing is printed

    • A disp()

    Correct Answer
    A. A disp()
    Explanation
    The code defines a class A with a method disp() that prints "A disp()". Then, a class B is defined which inherits from class A. An object obj is created from class B and the disp() method is called on it. Since class B inherits from class A, it also has access to the disp() method. Therefore, when obj.disp() is called, it will print "A disp()".

    Rate this question:

  • 42. 

     What type of inheritance is illustrated in the following Python code? class A():     pass class B(A):     pass class C(B):     pass

    • Multi-level inheritance

    • Multiple inheritance

    • Hierarchical inheritance

    • Single-level inheritance

    Correct Answer
    A. Multi-level inheritance
    Explanation
    The given Python code demonstrates multi-level inheritance. In multi-level inheritance, a class is derived from another derived class. In this code, class B is derived from class A, and class C is derived from class B. This creates a hierarchy of classes, where each derived class inherits the attributes and methods of its parent class. Therefore, the correct answer is multi-level inheritance.

    Rate this question:

  • 43. 

     What will be the output of the following Python code? class A:     def test(self):         print("test of A called") class B(A):     def test(self):         print("test of B called")         super().test()   class C(A):     def test(self):         print("test of C called")         super().test() class D(B,C):     def test2(self):         print("test of D called")       obj=D() obj.test()

    • Test of B called test of C called test of A called

    • Test of C called test of B called

    • Test of C called test of B called

    • Error, all the three classes from which D derives has same method test()

    Correct Answer
    A. Test of B called test of C called test of A called
    Explanation
    The code defines four classes: A, B, C, and D. Class A has a method called test() which prints "test of A called". Class B and C both inherit from class A and override the test() method. Class B's test() method prints "test of B called" and then calls the test() method of its superclass using the super() function. Class C's test() method prints "test of C called" and also calls the test() method of its superclass using the super() function. Class D inherits from both class B and C. When an object of class D is created and the test() method is called, it first calls the test() method of class B, which prints "test of B called" and then calls the test() method of class C, which prints "test of C called". Finally, the test() method of class A is called, which prints "test of A called". Therefore, the output of the code is "test of B called", "test of C called", "test of A called".

    Rate this question:

  • 44. 

     Suppose d = {“john”:40, “peter”:45}, to delete the entry for “john” what command do we use?

    • D.delete(“john”:40)

    • D.delete(“john”)

    • Del d[“john”]

    • Del d(“john”:40)

    Correct Answer
    A. Del d[“john”]
    Explanation
    To delete the entry for "john" in the dictionary, we use the command "del d['john']". This command removes the key-value pair with the key "john" from the dictionary "d".

    Rate this question:

  • 45. 

    def func(x, ans): if(x==0): return 0 else: return func(x-1, x+ans) print(func(2,0))

    • 0

    • 1

    • 2

    • 3

    Correct Answer
    A. 0
    Explanation
    The function "func" takes two parameters, x and ans. It checks if x is equal to 0. If it is, the function returns 0. If x is not equal to 0, the function recursively calls itself with x-1 and x+ans as the new parameters. In the given code, the function is called with x=2 and ans=0. Since x is not equal to 0, the function calls itself again with x=1 and ans=2. Again, x is not equal to 0, so the function calls itself once more with x=0 and ans=3. This time, x is equal to 0, so the function returns 0. Therefore, the output of the code is 0.

    Rate this question:

  • 46. 

     Which of the following is not a keyword?

    • Eval

    • Assert

    • Nonlocal

    • Pass

    Correct Answer
    A. Eval
    Explanation
    The keyword "eval" is not a valid keyword in Python. It is a built-in function that evaluates and executes a string as Python code. The other options, "assert", "nonlocal", and "pass", are all valid keywords in Python. "assert" is used for debugging and testing purposes, "nonlocal" is used to declare a variable in an outer function scope, and "pass" is a placeholder statement used when no action is required.

    Rate this question:

  • 47. 

    What will be the output of the following Python code? def foo(i, x=[]):     x.append(i)     return x for i in range(3):     print(foo(i))

    • [0] [1] [2]

    • [0] [0, 1] [0, 1, 2]

    • [1] [2] [3]

    • [1] [1, 2] [1, 2, 3]

    Correct Answer
    A. [0] [0, 1] [0, 1, 2]
    Explanation
    The function foo takes two parameters, i and x, with x having a default value of an empty list. Inside the function, the value of i is appended to the list x using the append method. The function then returns the modified list x.

    In the given code, a for loop is used to iterate over the range from 0 to 2. In each iteration, the foo function is called with the current value of i. The output of each function call is printed.

    Since the default value of x is an empty list, the first function call foo(0) will append 0 to the empty list and return [0]. The second function call foo(1) will use the modified list [0] as the default value of x and append 1 to it, resulting in [0, 1]. The third function call foo(2) will use the modified list [0, 1] as the default value of x and append 2 to it, resulting in [0, 1, 2].

    Therefore, the output of the given code will be [0] [0, 1] [0, 1, 2].

    Rate this question:

  • 48. 

     To open a file c:\scores.txt for reading, we use _____________

    • Infile = open(“c:\scores.txt”, “r”)

    • Infile = open(“c:\\scores.txt”, “r”)

    • Infile = open(file = “c:\scores.txt”, “r”)

    • Infile = open(file = “c:\\scores.txt”, “r”)

    Correct Answer
    A. Infile = open(“c:\\scores.txt”, “r”)
    Explanation
    The correct answer is "infile = open(“c:\\scores.txt”, “r”)" because it uses the correct syntax to open a file named "scores.txt" located in the "c:\" directory for reading. The double backslashes are used to escape the backslash character in the file path, and the "r" parameter specifies that the file should be opened in read mode.

    Rate this question:

  • 49. 

    What will be the output of the following Python code? x = ['ab', 'cd'] for i in x:     i.upper() print(x)

    • [‘ab’, ‘cd’]

    • [‘AB’, ‘CD’]

    • [None, None]

    • None of the mentioned

    Correct Answer
    A. [‘ab’, ‘cd’]
    Explanation
    The code will output ['ab', 'cd']. This is because the code creates a list x with two elements 'ab' and 'cd'. Then, it iterates over each element in the list using a for loop. Inside the loop, the upper() method is called on each element, which converts the element to uppercase. However, since the upper() method returns a new string and does not modify the original string, the changes are not reflected in the list x. Therefore, when the print statement is executed, it prints the original list x as ['ab', 'cd'].

    Rate this question:

Quiz Review Timeline (Updated): Mar 20, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 08, 2019
    Quiz Created by
    Vaibhav99aggarwa
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.