Python

A visually appealing illustration of a programmer surrounded by Python code, books, and various programming icons, showcasing the theme of Python programming and learning.

Python Programming Quiz

Test your knowledge of Python with this engaging quiz designed for developers of all levels. Featuring 10 multiple-choice questions, this quiz covers a wide range of topics including data structures, functions, and object-oriented programming.

Challenge yourself with questions such as:

  • What does the function re.search do?
  • Which of these is a private data field?
  • What is the output of various Python code snippets?
10 Questions2 MinutesCreated by CodingMaster25
1. What does the function re.search do?
A) matches a pattern at the start of the string
B) matches a pattern at any position in the string
C) such a function does not exist
D) none of the mentioned

2. Which of these is a private data field?

def Demo:
def __init__(self):
    __a = 1
    self.__b = 1
    self.__c__ = 1
    __d__= 1
A) __a
B) __b
C) __c__
D) __d__
3. Which of the following is the use of id() function in python?
A) Id returns the identity of the object
B) Every object doesn’t have a unique id
C) All of the mentioned
D) None of the mentioned

4. What is the output of the following piece of code?

class A:
    def __str__(self):
        return '1'
class B(A):
    def __init__(self):
        super().__init__()
class C(B):
    def __init__(self):
        super().__init__()
def main():
    obj1 = B()
    obj2 = A()
    obj3 = C()
    print(obj1, obj2,obj3)
main()
A) 1 1 1
B) 1 2 3
C) ‘1’ ‘1’ ‘1’
D) An exception is thrown
5. The nested list undergoes shallow copy even when the list as a whole undergoes deep copy. State whether this statement is true or false.
A) True
B) False
6. What is the output of the above code?
A) {‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
B) (‘horses’, ‘are’, ‘fast’)
C) ‘horses are fast’
D) ‘are’
7. What is the output of the codes shown below?
A) False, False
B) False, True
C) True, True
D) True, False
8. Let A and B be objects of class Foo. Which functions are called when print(A + B) is executed?
A) __add__(), __str__()
B) __str__(), __add__()
C) __sum__(), __str__()
D) __str__(), __sum__()
9. To read the remaining lines of the file from a file object infile, we use
A) infile.read(2)
B) infile.read()
C) infile.readline()
D) infile.readlines()

10. What is the output of the following?

try:
    if '1' != 1:
        raise "someError"
    else:
        print("someError has not occured")
except "someError":
    print ("someError has occured")
A) someError has occured
B) someError has not occured
C) invalid code
D) none of the mentioned
{"name":"Python", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Test your knowledge of Python with this engaging quiz designed for developers of all levels. Featuring 10 multiple-choice questions, this quiz covers a wide range of topics including data structures, functions, and object-oriented programming.Challenge yourself with questions such as:What does the function re.search do?Which of these is a private data field?What is the output of various Python code snippets?","img":"https:/images/course1.png"}
Powered by: Quiz Maker