Python QuestionsBy Kritika Papne / March 20, 2023 0 votes, 0 avg 656 123456789101112131415 Python Questions 1 / 15 1. Which of the following is a feature of DocString? A. Provide a convenient way of associating documentation with Python modules, functions, classes, and methods B. All functions should have a docstring C. Docstrings can be accessed by the __doc__ attribute on objects D. All of the mentioned 2 / 15 2. What will be the output of the following code snippet? a = "4, 5" nums = a.split(',') x, y = nums int_prod = int(x) * int(y) print(int_prod) A. 20 B. 45 C. 54 D. 4, 5 3 / 15 3. Which of the following are valid string manipulation functions in Python? A. count() B. upper() C. strip() D. All of the above 4 / 15 4. 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) A. x is 50 Changed global x to 2 Value of x is 50 B. x is 50 Changed global x to 2 Value of x is 2 C. x is 50 Changed global x to 50 Value of x is 50 D. None of the mentioned 5 / 15 5. What is called when a function is defined inside a class? A. Module B. Class C. Another Function D. Method 6 / 15 6. Which of the following is used to define a block of code in Python language? A. Indentation B. Keys C. Brackets D. All of the above 7 / 15 7. How can assertions be disabled in Python? A. passing -O when running python B. assertions are disabled by default C. both A and B are wrong D. Assertions cannot be disabled in python 8 / 15 8. In Python, ___ defines a block of statements. A. Block B. Loop C. Indentation D. None of the mentioned above 9 / 15 9. What will be the output of the following Python code? x = 50 def func(x): print('x is', x) x = 2 print('Changed local x to', x) func(x) print('x is now', x) A. x is 50 Changed local x to 2 x is now 50 B. x is 50 Changed local x to 2 x is now 2 C. x is 50 Changed local x to 2 x is now 100 D. None of the mentioned 10 / 15 10. What will be the output of the following Python code? import re s = 'abc123 xyz666 lmn-11 def77' re.sub(r'b([a-z]+)(d+)', r'21:', s) A. ‘123abc: 666xyz: lmn-11 77def:’ B. ‘77def: lmn-11: 666xyz: 123abc’ C. ‘abc123:’, ‘xyz666:’, ‘lmn-11:’, ‘def77:’ D. ‘abc123: xyz666: lmn-11: def77’ 11 / 15 11. What will be the output of the following program? i = 0 while i < 5: print(i) i += 1 if i == 3: break else: print(0) A. 1 2 3 B. 0 1 2 3 C. 0 1 2 D. 3 2 1 12 / 15 12. Consider the results of a medical experiment that aims to predict whether someone is going to develop myopia based on some physical measurements and heredity. In this case, the input dataset consists of the person’s medical characteristics and the target variable is binary: 1 for those who are likely to develop myopia and 0 for those who aren’t. This can be best classified as A. Regression B. Decision Tree C. Clustering D. Association Rules 13 / 15 13. What will be the output of the following Python code? x = "abcdef" i = "a" while i in x: x = x[:-1] print(i, end = " ") A. i i i i i i B. a a a a a a C. a a a a a D. none of the mentioned 14 / 15 14. Which of the following modules need to be imported to handle date time computations in Python? A. datetime B. date C. time D. timedate 15 / 15 15. What will be the output of the following Python code? class test: def __init__(self,a): self.a=a def display(self): print(self.a) obj=test() obj.display() A. Runs normally, doesn’t display anything B. Displays 0, which is the automatic default value C. Error as one argument is required while creating the object D. Error as display function requires additional argument Your score isThe average score is 40% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Written by Shubhranshu Shekhar, who has trained 20000+ students in coding. Kritika Papne