Python Questions

0 votes, 0 avg
454

Python Questions

1 / 15

1. Which of the following are valid escape sequences in Python?

2 / 15

2. What will be the output of the following Python code?

class Demo:
    def __new__(self):
        self.__init__(self)
        print("Demo's __new__() invoked")
    def __init__(self):
        print("Demo's __init__() invoked")
class Derived_Demo(Demo):
    def __new__(self):
        print("Derived_Demo's __new__() invoked")
    def __init__(self):
        print("Derived_Demo's __init__() invoked")
def main():
    obj1 = Derived_Demo()
    obj2 = Demo()
Main()

3 / 15

3. What will be the output of the following Python code if the input entered is 6?

valid = False
while not valid:
    try:
        n=int(input("Enter a number"))
        while n%2==0:
            print("Bye")
        valid = True
    except ValueError:
        print("Invalid")

4 / 15

4. Which of the following is used to define a block of code in Python language?

5 / 15

5. Which of these is the definition for packages in Python?

6 / 15

6. What is Instantiation in terms of OOP terminology?

7 / 15

7. As what datatype are the *args stored, when passed into a function?

8 / 15

8. What is the order of precedence in python?

9 / 15

9.

Which of the following is the proper syntax to check if a particular element is present in a list?

10 / 15

10. Which of the following is a feature of DocString?

11 / 15

11. Which of the following functions can be used to read data from a file using a file descriptor?

12 / 15

12. The following python program can work with ____ parameters.

def f(x):
    def f1(*args, **kwargs):
           print("JAVA")
           return x(*args, **kwargs)
    return f1

13 / 15

13. In Python, ___ defines a block of statements.

14 / 15

14. What keyword is used in Python to throw exceptions?

15 / 15

15. What will be the value of ‘result’ in following Python program?

list1 = [1,2,3,4]
list2 = [2,4,5,6]
list3 = [2,6,7,8]
result = list()
result.extend(i for i in list1 if i not in (list2+list3) and i not in result)
result.extend(i for i in list2 if i not in (list1+list3) and i not in result)
result.extend(i for i in list3 if i not in (list1+list2) and i not in result)

Your score is

The average score is 35%

0%