Python quiz questions

Python interview questions

  • 1.

    What Relationship Is Suited For Course And Faculty?

    1. association

    2. composition

    3. inheritance

    4. None of the above

    Answer
  • 2.

    What Relationship Correctly Fits For University And Professor?

    1. association

    2. composition

    3. inheritance

    4. All of the above

    Answer
  • 3.

    Which Of The Following Statements Can Be Used To Check, Whether An Object “Obj” Is An Instance Of Class A Or Not?

    1. obj.isinstance(A)

    2. A.isinstance(obj)

    3. isinstance(obj, A)

    4. isinstance(A, obj)

    Answer
  • 4.

    What Will Be The Output Of The Following Code Snippet?

    class A:
        def __init__(self):
            self.calcI(30)
            
        def calcI(self, i):
            self.i = 2 * i;
     
    class B(A):
        def __init__(self):
            super().__init__()
            print("i from B is", self.i)
            
        def calcI(self, i):
            self.i = 3 * i;
     
    b = B()

     

    1. The __init__ method of only class B gets invoked.

    2. The __init__ method of class A gets invoked and it displays “i from B is 0”.

    3. The __init__ method of class A gets invoked and it displays “i from B is 60”.

    4. The __init__ method of class A gets invoked and it displays “i from B is 90”.

    Answer
  • 5.

    What Will Be The Output Of The Following Code Snippet?

    class A:
        def __init__(self):
            self.calcI(30)
            print("i from A is", self.i)
     
        def calcI(self, i):
            self.i = 2 * i;
     
    class B(A):
        def __init__(self):
            super().__init__()
            
        def calcI(self, i):
            self.i = 3 * i;
     
    b = B()

     

    1. The __init__ method of only class B gets invoked.

    2. The __init__ method of class A gets invoked and it displays “i from A is 0”.

    3. The __init__ method of class A gets invoked and it displays “i from A is 60”.

    4. The __init__ method of class A gets invoked and it displays “i from A is 90”.

    Answer
  • 6.

    Which Of The Following Statements Is True?

    1. By default, the __new__() method invokes the __init__ method.

    2. The __new__() method is defined in the object class.

    3. The __init__() method is defined in the object class.

    4. The __str__() method is defined in the object class.

    5. The __eq__(other) method is defined in the object class.

    Answer
  • 7.

    Which Of The Following Statements Are Correct About The Given Code Snippet?

    class A:
        def __init__(self, i = 0):
            self.i = i
     
    class B(A):
        def __init__(self, j = 0):
            self.j = j
     
    def main():
        b = B()
        print(b.i)
        print(b.j)
     
    main()

     

    1. Class B inherits A, but the data field “i” in A is not inherited.

    2. Class B inherits A, thus automatically inherits all data fields in A.

    3. When you create an object of B, you have to pass an argument such as B(5).

    4. The data field “j” cannot be accessed by object b.

    Answer
  • 8.

    Which Of The Following Can Be Used To Invoke The __init__ Method In B From A, Where A Is A Subclass Of B?

    1. super().__init__()

    2. super().__init__(self)

    3. B.__init__()

    4. B.__init__(self)

    Answer
  • 9.

    What Will Be The Output Of The Following Code Snippet?

    class Person:
        def __init__(self, id):
            self.id = id
     
    sam = Person(100)
     
    sam.__dict__['age'] = 49
     
    print (sam.age + len(sam.__dict__))

     

    1. 1

    2. 2

    3. 49

    4. 50

    5. 51

    Answer
  • 10.

    What Will Be The Output Of The Following?

    s = "\t\tWelcome\n"
    print(s.strip())

     

    1. \t\tWelcome\n

    2. Welcome\n

    3. \t\tWELCOME

    4. Welcome

    Answer
  • 11.

    Which Of The Following Statements Are Correct?

    1. A reference variable is an object.

    2. A reference variable refers to an object.

    3. An object may contain other objects.

    4. An object can contain the references to other objects.

    Answer
  • 12.

    What Will Be The Output Of The Following Code Snippet?

    class Sales:
        def __init__(self, id):
            self.id = id
            id = 100
     
    val = Sales(123)
    print (val.id)

     

    1. SyntaxError, this program will not run

    2. 100

    3. 123

    4. None of the above

    Answer
  • 13.

    Which Of The Following Statements Is Most Accurate For The Declaration X = Circle()?

    1. x contains an int value.

    2. x contains an object of the Circle type.

    3. x contains a reference to a Circle object.

    4. You can assign an int value to x.

    Answer
  • 14.

    Which Of The Following Is Required To Create A New Instance Of The Class?

    1. A constructor

    2. A class

    3. A value-returning method

    4. A None method

    Answer
  • 15.

    Which Of The Following Keywords Mark The Beginning Of The Class Definition?

    1. def

    2. return

    3. class

    4. All of the above.

    Answer
  • 16.

    Which Of The Following Represents A Template, Blueprint, Or Contract That Defines Objects Of The Same Type?

    1. A class

    2. An object

    3. A method

    4. A data field

    Answer
  • 17.

    Which Of The Following Represents A Distinctly Identifiable Entity In The Real World?

    1. A class

    2. An object

    3. A method

    4. A data field

    Answer
  • 18.

    Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]

    What is max(list1)? 

    1. 5

    2. 4

    3. 8

    4. 25

    5. 1

    Answer
  • 19.

    Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3]

    What is len(list1)? 

    1. 5

    2. 6

    3. 7

    4. 8

    Answer
  • 20.

    What is list("abcd")?

    1. A. ['a', 'b', 'c', 'd']

    2. B. ['ab']

    3. C. ['cd']

    4. D. ['abcd']

    Answer

© 2017 QuizBucket.org