Python QuestionsBy Kritika Papne / March 20, 2023 0 votes, 0 avg 654 123456789101112131415 Python Questions 1 / 15 1. What will be the output of the following code snippet? count = 0 while(True): if count % 3 == 0: print(count, end = " ") if(count > 15): break; count += 1 A. 0 1 2 ….. 15 B. infinite loop C. 0 3 6 9 12 15 D. 0 3 6 9 12 2 / 15 2. Which of the following functions can be used to read data from a file using a file descriptor? A. os.reader() B. os.read() C. os.quick_read() D. os.scan() 3 / 15 3. What will be the output of the following Python program? z=set('abc') z.add('san') z.update(set(['p', 'q'])) Z A. {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’} B. {‘abc’, ‘p’, ‘q’, ‘san’} C. {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’} D. {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san} 4 / 15 4. What are the two main types of functions in Python? A. System function B. Custom function C. Built-in function & User defined function D. User function 5 / 15 5. What is the order of precedence in python? A. Exponential, Parentheses, Multiplication, Division, Addition, Subtraction B. Exponential, Parentheses, Division, Multiplication, Addition, Subtraction C. Parentheses, Exponential, Multiplication, Division, Subtraction, Addition D. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction 6 / 15 6. The % operator returns the ___. A. Quotient B. Divisor C. Remainder D. None of the mentioned above 7 / 15 7. As what datatype are the *kwargs stored, when passed into a function? A. list B. tuple C. dictionary D. none of the above 8 / 15 8. What is the order of namespaces in which Python looks for an identifier? A. Python first searches the built-in namespace, then the global namespace and finally the local namespace B. Python first searches the built-in namespace, then the local namespace and finally the global namespace C. Python first searches the local namespace, then the global namespace and finally the built-in namespace D. Python first searches the global namespace, then the local namespace and finally the built-in namespace 9 / 15 9. Which of the following are valid escape sequences in Python? A. n B. t C. \ D. all of the above 10 / 15 10. Which of the following functions can help us to find the version of python that we are currently working on? A. sys.version(1) B. sys.version(0) C. sys.version() D. sys.version 11 / 15 11. What will be the output of the following code snippet? a = [1, 2, 3] a = tuple(a) a[0] = 2 print(a) A. [2,2,3] B. (2,2,3) C. (1,2,3) D. error 12 / 15 12. 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 13 / 15 13. Which one of the following syntaxes is the correct syntax to read from a simple text file stored in ”d:python.txt”? A. Infile = open(file=''d:\python.txt'', ''r'') B. Infile = open(''d:python.txt'',''r'') C. Infile = open(''d:\python.txt'', ''r'') D. Infile = open.file(''d:\python.txt'',''r'') 14 / 15 14. 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’ 15 / 15 15. 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 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