Python quiz questions

Python interview questions

  • 1.

    What is the output when following statement is executed?

    str='good-BYE'
    print  (str.capitalize())
    1. GOOD-BYE

    2. Good-bye

    3. GOOD-bye

    4. Good-Bye

    Answer
  • 2.

    Which of the answers would print the output as given below?

    C:\Common\TestString.doc
    1. str='C:\\Common\TestString.doc'
      print  (str)
    2. str='C:\Common\TestStri\ng.doc'
      print  (str)
    3. str='C:\\Commo\n\TestSt\ring.doc'
      print  (str)
    4. str='''C:\\Common\testString.doc'''
      print  (str)
    Answer
  • 3.

    Which of the following is the output of the following Python instruction?

    print  ('am'.zfill(5))
    1. 000am

    2. 00am0

    3. 0am00

    4. am000

    Answer
  • 4.

    Which of the following is the output of the below Python code snippet?

    str='PYTHON\nString\nConcepts'
    print  (str.splitlines())
    1. ['PYTHON', '\nString', '\nConcepts']

    2. ['PYTHON\n', 'String\n', 'Concepts']

    3. ['PYTHON\n', 'String\n', 'Concepts\n']

    4. ['PYTHON', 'String', 'Concepts']

    Answer
  • 5.

    Which of the following is the output of the below Python code?

    str='abbabadaadbbaccabc'
    print  (str.count('ab',2))
    1. 2

    2. 3

    3. 5

    4. 4

    Answer
  • 6.

    Which of the following print statements will print all the names in the list on a separate line?

    identity = ['Python', 'Python quiz', 'Python String', 'Python Interview', 'Python questions']
    1. print (identity.join("\n") )

    2. print (identity.concatenate("\n") )

    3. print (identity.join("%s\n", names))

    4. print ("\n".join(identity))

    Answer
  • 7.

    Which of the following is the output of the below Python code?

    str='abcdefcdyzcd'
    print  (str.split('cd',2))
    1. ['ab','ef','yz']

    2. ['ab','efcdyzcd']

    3. ['ab','ef','yzcd']

    4. ['abcdef','yzcd']

    Answer
  • 8.

    What is the output when the following instruction is executed?

    print  ('+55'.zfill(5))
    1. 00+55

    2. +++55

    3. +0055

    4. 00055

    Answer
  • 9.

    Which of the following is the output of the below Python code?

    print  (u'2.15'.isnumeric())
    1. True

    2. Error will be generated.

    3. None

    4. False

    Answer
  • 10.

    Which of the following is the output of the following Python code?

    str='PYTHON string concepts'
    print  (str.title())
    1. PYTHON STRING CONCEPTS

    2. None

    3. PYTHON String Concepts

    4. Python String Concepts

    Answer
  • 11.

    What is the default value of encoding in the string function encode()?

    1. utf-8

    2. qwerty

    3. utf-16

    4. ascii

    Answer
  • 12.

    What is the output when following statement is executed?

    str='[email protected]!!'
    print  (str.lower())
    1. [email protected]!!

    2. None

    3. hellojohn

    4. [email protected]!!

    Answer
  • 13.

    Which of the following is the output of the below Python code?

    str='python'
    print  (str.center(15,'*'))
    1. ********python*******

    2. *****python****

    3. ****python*****

    4. ********python*******

    Answer
  • 14.

    What is the output when following statement is executed?

    str='abcdefcdyz'
    print  (str.partition('cd'))
    1. ('ab','cd','ef','cd','yz')

    2. ('ab','ef','yz')

    3. ('ab','cd','efcdyz')

    4. ('abcdef','cd','yz')

    Answer
  • 15.

    Which of the following is the output of the below Python code?

    str='abababadaadbbaccabc'
    print  (str.count('ab',-17,-1))
    1. 2

    2. 4

    3. 3

    4. 5

    Answer
  • 16.

    Which of the following is the output of the below Python code?

    str='example'
    print  (str.center(10,'*'))
    1. *****example*****

    2. **example*

    3. *example**

    4. *example *

    Answer
  • 17.

    What Will Be The Output Of The Following Code Snippet?

    class A:
        def __getInfo(self):
            return "A's getInfo is called"
      
        def printInfo(self):
            print(self.__getInfo(), end = ' ')
     
    class B(A):
        def __getInfo(self):
            return "B's getInfo is called"
     
    def main():
        A().printInfo()
        B().printInfo()
     
    main()

     

    1. A’s getInfo is called A’s getInfo is called 

    2. A’s getInfo is called B’s getInfo is called 

    3. B’s getInfo is called A’s getInfo is called 

    4. B’s getInfo is called B’s getInfo is called

    Answer
  • 18.

    What Will Be The Output Of The Following Code Snippet?

    class A:
        def getInfo(self):
            return "A's getInfo is called"
      
        def printInfo(self):
            print(self.getInfo(), end = ' ')
     
    class B(A):
        def getInfo(self):
            return "B's getInfo is called"
     
    def main():
        A().printInfo()
        B().printInfo()
     
    main()

     

    1. A’s getInfo is called A’s getInfo is called 

    2. A’s getInfo is called B’s getInfo is called 

    3. B’s getInfo is called A’s getInfo is called 

    4. B’s getInfo is called B’s getInfo is called

    Answer
  • 19.

    What Will Be The Output Of The Following Code Snippet?

    class A:
        def __init__(self, x = 2, y = 3):
            self.x = x
            self.y = y
     
        def __str__(self):
            return "A"
     
        def __eq__(self, num ):
            return self.x * self.y == num.x * num.y
     
    def main():
        a = A(1, 2)
        b = A(2, 1)
        print(a == b)
     
    main()

     

    1. True

    2. False

    3. 2

    4. 1

    Answer
  • 20.

    What Will Be The Output Of The Following Code Snippet?

    class A:
        def __str__(self):
            return "A"
     
    class B(A):
        def __init__(self):
            super().__init__()
     
    class C(B):
        def __init__(self):
            super().__init__()
     
    def main():
        b = B()
        a = A()
        c = C()
        print(a, b, c)
     
    main()

     

    1. B B B

    2. A B C

    3. C B A

    4. A A A

    Answer

© 2017 QuizBucket.org