Python MCQ Part - 21) Study the following program: What will be the output of this program?
Answer: (a) javatpoint None None Explanation: In this program, the inner print function will run first as compared to the outer print function. Therefore, the correct output of this program is "javatpoint None None". 2) Study the following program: What will be the output of this program?
Answer: (b) 1.0 Explanation: Binary values True = 1 False = 0 (1 ** 0 / 1) = (10/ 1) = 1.0 Therefore, option (b) is the correct output of this program. 3) Study the following program: What will be the output of this program?
Answer: (b) 4 Explanation: In the Python Programming Language, Increment and Decrement condition is not valid. (y = ++y) = (y = y) So, the output of this program is 4. 4) Study the following program: What will be the output of this program?
Answer: (c) 0 Explanation: In the Python Programming Language, Increment and Decrement condition is not valid. int1 = (10) int2 = (6) int2 = ++int1 int2 = 10 print(10 - 10) So, the output of this program is the 0. 5) Study the following program: What will be the output of this program?
Answer: (d) 11.0 Explanation: Precedence table in python
If the operator precedence is same, the calculation starts from left to right. Therefore, option (d) is the correct output of this program. 6) Study the following program: What will be the output of this program?
Answer: (b) 2 Explanation: "0b0010" value is a binary value. Therefore, option (b) is the correct output of this program. 7) Study the following program: What will be the output of this program?
Answer: (b) j a v a t p o i n t Explanation: When a user prints a string with "*", that string is printed with the space in each word. Therefore, option (b) is the correct output of this program. 8) Study the following program: What will be the output of this program?
Answer: (c) (2, 10, 3, 5) Explanation: "i" and "j" are tuples values. The tuple values are added to the bracket. Therefore, option (c) is the correct output of this program. 9) Study the following program: What will be the output of this program?
Answer: (d) 7 Explanation: In the python programming language, (int(6 == 6.0)) is a valid condition but in other languages is not a valid condition. Therefore, option (d) is the correct output of this program. 10) Study the following program: What will be the output of this program?
Answer: (d) TypeError Explanation: In this program, "i" is the integer value, and "j" is the tuple value. The integer and tuple values cannot be added in the python programming language. Therefore, this program will print the "Typeerror". 11) How many control statements python supports?
Answer: (c) Three Explanation: In the Python Programming Language, there are three types of control statements.
12) How many keywords present in the python programming language?
Answer: (c) 33 Explanation: There are 33 keywords in python. In the Python Programming Language, keywords are reserved words for the program that is used to define the syntax and structure. You cannot use a keyword as a function name, variable name, or any other identifier. 13) Which of the following arithmetic operators cannot be used with strings in python?
Answer: (c) - Explanation: In python, only (+) and (*), two arithmetic operators are used with string. Therefore, option (c) is the correct answer. 14) Study the following program: What will be the output of this program?
Answer: (c) java2point Explanation: The "sep" means separator that is used to add a separator between the two strings. Therefore, option (c) is the correct output of this program. 15) Study the following program: What will be the output of this program?
Answer: (a) It's ok, don't worry Explanation: In the Python programming language, the backslash "\" is an escape character. Therefore, option (a) is the correct output of this program. 16) Study the following program: What will be the output of this program?
Answer: (d) 1 2 3 4 5 6 Explanation: "_" is a valid variable name. Therefore, option (d) is the correct output of this program. 17) Which of the following keywords is not reversed keyword in python?
Answer: (c) goto Explanation: "and", "class", and "None" are reversed keywords in python. So, option (c) is the correct answer. 18) Study the following program: What will be the output of this program?
Answer: (a) 1 2 1 2 Explanation:
19) Study the following program: What will be the output of this program?
Answer: (d) z Explanation: The ASCII value of the a-z lies in the range 97 - 122. So, the maximum value of the string is 122 (z = 122). 20) Study the following program: What will be the output of this program?
Answer: (d) NameError Explanation: This program will print the NameError because 'x' is not defined in this code. 21) PVM is often called _________.
Answer: (a) Python interpreter Explanation: PVM is a software that converts bytecode to machine code for a given OS. PVM is also called Python Interpreter, and that is why Python is called Interpreted Language. 22) Study the following program: What will be the output of this program?
Answer: (b) 2 3 4 5 6 Explanation: This is a valid syntax of the update function. Therefore, the option (b) is the correct output of this program. 23) Study the following program: What will be the output of this program?
Answer: (d) AttributeError Explanation: In this program, "i" is the tuple value. The tuple value cannot be sorted in python language. Therefore, this program will print the "AttributeError". 24) Which of the following keywords is used for function declaration in Python language?
Answer: (a) def Explanation: In the python language, the def keyword is used to define the function. Syntax of the function declaration def function_name(parameters): block of function return expression 25) Which of the following objects are present in the function header in python?
Answer: (a) Function name and Parameters Explanation: Function name and Parameter are both present in the function header in python. def function_name(parameters): block of function return expression 26) When a user does not use the return statement inside a function in Python, what will return the function in that case.
Answer: (c) None Explanation: When a user does not use the return statement inside a function in Python, the function will return the "None". 27) Which one of the following is the right way to call a function?
Answer: (c) function_name() Explanation: To call a function in python language, it uses the function name followed by the parentheses. 28) Suppose a user wants to print the second value of an array, which has 5 elements. What will be the syntax of the second value of the array?
Answer: (b) array[1] Explanation: The index of the array starts with 0. Therefore, the option (b) is the correct answer. 29) Study the following program: What will be the output of this program?
Answer: (c) python language Explanation: In this program, it will print the value of the str1. Therefore, the option (c) is the correct output of this program. 30) Study the following program: What will be the output of this program?
Answer: (b) 4 Explanation: The output of this program is 4. 31) Study the following expression: What type of data is in this expression?
Answer: (c) List of tuples Explanation: The variable str has a list of tuples attached to it. Hence it is a list of tuples. So, option (c) is the correct answer. 32) Which of the following statements is not valid regarding the variable in python?
Answer: (c) The variable_name can begin with a number Explanation: The variable_name can begin with alphabets or underscore but cannot begin with numbers. So, option (c) is the correct answer. 33) Study the following program: How many times will this program run the loop?
Answer: (b) 102 Explanation: This loop will run the 1 to -100 (1, 0, -1,?, -100). So, option (b) is the correct answer. 34) Study the following program: What will be the output of this program?
Answer: (a) 32 0 Explanation: The output of this program is (32, 0). 35) Which of the following statements is valid for "if statement"?
Answer: (a) if f >= 12: Explanation: The "if statement" always ends with a colon (:). So, option (a) is the correct statement. 36) Which of the following blocks allows you to test the code blocks for errors?
Answer: (b) try block Explanation: The try block allows you to test the code blocks for errors in the python language. 37) Study the following program: What will be the output of this program?
Answer: (c) error comes in the line Explanation: The try block will generate an error because file_name is not defined in the program. Therefore, the output of this program will be "error comes in the line". 38) Study the following program: What will be the output of this program?
Answer: (b) 8 Explanation: In this program, the assert keyword has been used to mislead the user. Therefore, this program will print the value of "j". 39) Study the following program: How many objects are there for the given program?
Answer: (c) 3 Explanation: There will be three objects created in this program. Therefore, the option (c) is the correct answer. 40) Study the following program: Which of the following statements is incorrect regarding this program?
Answer: (d) None of the these Explanation: All statements are correct. So, the option (d) is the correct answer. 41) Study the following program: Which of the following statements is incorrect regarding this program?
Answer: (b) 20 30 Explanation: The output of this program is (20 30). 42) Which of the following code will create a set in python language? 1. thisset = (("apple", "banana", "cherry")) 2. thisset = ("car", "bike", "123") 3. thisset = {}
Answer: (c) 1, 2, and 3 create a set Explanation: All codes will create a set. So, option (c) is the correct answer. 43) Study the following program: What will be the output of this program?
Answer: (c) {0, 9, 'a1'} Explanation: The output of this program is {0, 9, 'a1'} 44) Which of the following statements would create a tuple in python?
Answer: (a) mytuple = ("apple", "banana", "cherry") Explanation: Option (a) is the correct syntax for a tuple. So, option (a) is the correct answer. 45) Study the following program: What will be the output of this program?
Answer: (c) AttributeError Explanation: In this program, "mytuple1" is the tuple value. In the python language, the pop () method cannot be used with tuple value. Therefore, this program will print the "AttributeError". 46) Which of the following functions returns a list containing all matches?
Answer: (b) findall Explanation: The findall function is the most powerful function in python language that returns a list containing all matches. 47) Study the following program: What will be the output of this program?
Answer: (a) (2, 4, 3, 2, 4, 3) Explanation: The output of this program is (2, 4, 3, 2, 4, 3). 48) In the Python Programming Language, syntax error is detected by ______ at _________.
Answer: (c) Interpreter / Run time Explanation: In the Python Programming Language, the interpreter can detect a syntax error at run time. The syntax error is a spelling-like mistake in the source code. 49) Study the following program: What will be the output of this program?
Answer: (b) 10 11 11 13 Explanation: The value of i[-2] changes in each iteration. 50) Which of the following blocks allows you to handle the errors?
Answer: (a) except block Explanation: The except block allows you to handle the errors. Next Topic# |