Javatpoint Logo
Javatpoint Logo

Python MCQ Part - 2

1) Study the following program:

What will be the output of this program?

  1. javatpoint None None
  2. None None javatpoint
  3. None javatpoint None
  4. Javatpoint

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?

  1. True ** False / True
  2. 1.0
  3. 1 ** 0 / 1
  4. None of the these

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?

  1. 2
  2. 4
  3. 6
  4. None

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?

  1. 2
  2. 4
  3. 0
  4. No Output

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?

  1. 7
  2. 7.0
  3. 15
  4. 0

Answer: (d) 11.0

Explanation: Precedence table in python

High *, /, // and%
Low + and -

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?

  1. 0b0010
  2. 2
  3. NameError: name '0b0010' is not defined
  4. SyntaxError

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?

  1. javatpoint
  2. j a v a t p o i n t
  3. *word
  4. SyntaxError: invalid syntax

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?

  1. (5, 10)
  2. 20
  3. (2, 10, 3, 5)
  4. SyntaxError: invalid syntax

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?

  1. 22
  2. 18
  3. 20
  4. 7

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?

  1. 5, 5
  2. 5
  3. (2 , 3 , 5)
  4. TypeError

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?

  1. Four
  2. Five
  3. Three
  4. None of the these

Answer: (c) Three

Explanation: In the Python Programming Language, there are three types of control statements.

  1. Break
  2. Continue
  3. Pass statements

12) How many keywords present in the python programming language?

  1. 32
  2. 61
  3. 33
  4. 27

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?

  1. +
  2. *
  3. -
  4. All of the mentioned

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?

  1. javapoint2
  2. japoint
  3. java2point
  4. javapoin2

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?

  1. It's ok, don't worry
  2. It\'s ok, don\'t worry
  3. SyntaxError: EOL while scanning string literal
  4. SyntaxError: invalid syntax

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?

  1. SyntaxError: EOL while scanning string literal
  2. SyntaxError: invalid syntax
  3. NameError: name '_' is not defined
  4. 1 2 3 4 5 6

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?

  1. None
  2. class
  3. goto
  4. and

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?

  1. 1 2 1 2
  2. 2 4
  3. 0
  4. -1 -2 -1 -2

Answer: (a) 1 2 1 2

Explanation:

  • "a * 2" means, string prints 2 times.
  • "a * 0" means, string is empty.
  • Any string cannot be negative. Therefore, the string will not print any word.

19) Study the following program:

What will be the output of this program?

  1. 145
  2. 122
  3. a
  4. z

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?

  1. i i i i i i …
  2. 123789
  3. SyntaxError
  4. NameError

Answer: (d) NameError

Explanation: This program will print the NameError because 'x' is not defined in this code.


21) PVM is often called _________.

  1. Python interpreter
  2. Python compiler
  3. Python volatile machine
  4. Portable virtual machine

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?

  1. 2 3 4 4 5 6
  2. 2 3 4 5 6
  3. 4 5 6 2 3 4
  4. Error, duplicate element presents in list

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?

  1. 0 1 12 20 25
  2. 1 12 20 25
  3. FunctionError
  4. AttributeError

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?

  1. def
  2. function_name
  3. define
  4. None of the these

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?

  1. Function name and Parameters
  2. Only function name
  3. Only parameters
  4. None of the these

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.

  1. 0
  2. 1
  3. None
  4. No output

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?

  1. call function_name()
  2. function function_name()
  3. function_name()
  4. None of the these

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?

  1. array[2]
  2. array[1]
  3. array[-1]
  4. array[-2]

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?

  1. Print the index value of the p.
  2. p
  3. python language
  4. AttributeError

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?

  1. 12
  2. 4
  3. 11
  4. 16

Answer: (b) 4

Explanation: The output of this program is 4.


31) Study the following expression:

What type of data is in this expression?

  1. String type
  2. Array lists
  3. List of tuples
  4. str lists

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?

  1. The variable_name can begin with alphabets
  2. The variable_name can begin with an underscore
  3. The variable_name can begin with a number
  4. None of the these

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?

  1. Infinite
  2. 102
  3. 2
  4. 1

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?

  1. 32 0
  2. 0 32
  3. 18 0
  4. 0 18

Answer: (a) 32 0

Explanation: The output of this program is (32, 0).


35) Which of the following statements is valid for "if statement"?

  1. if f >= 12:
  2. if (f >= 122)
  3. if (f => 1222)
  4. if f >= 12222

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?

  1. except block
  2. try block
  3. finally block
  4. None of the these

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?

  1. file_name
  2. error
  3. error comes in the line
  4. file_name error comes in the line

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?

  1. 18
  2. 8
  3. No output
  4. TypeError

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?

  1. 1
  2. 2
  3. 3
  4. None of the these

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?

  1. A constructor has been given in this program
  2. id_no and age are called the parameters
  3. The "teac" is the reference variable for the object Teacher(5, 25)
  4. None of the these

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?

  1. 20 John 30
  2. 20 30
  3. John 30
  4. 30 John 20

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 = {}

  1. 1 only
  2. 1 and 2 both
  3. 1, 2, and 3 will create a set
  4. None of the these

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?

  1. {0, 0, 'a1', 0, 9}
  2. {0, 'a1', 0, 9}
  3. {0, 9, 'a1'}
  4. {0, 0, 9, 0, 'a1'}

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?

  1. mytuple = ("apple", "banana", "cherry")
  2. mytuple[123] = ("apple", "banana", "cherry")
  3. mytuple = ("2" * ("apple", "banana", "cherry"))
  4. None of the these

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?

  1. 5 1 7 6 2
  2. No output
  3. AttributeError
  4. None of the these

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?

  1. find
  2. findall
  3. search
  4. None of the these

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?

  1. (2, 4, 3, 2, 4, 3)
  2. (2, 2, 4, 4, 3, 3)
  3. (4, 8, 6)
  4. Error

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 _________.

  1. Interpreter / Compile time
  2. Run time / Interpreter
  3. Interpreter / Run time
  4. Compile time / Run time

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?

  1. 10 11 11 12
  2. 10 11 11 13
  3. 10 8 6 4
  4. SyntaxError

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?

  1. except block
  2. try block
  3. finally block
  4. None of the these

Answer: (a) except block

Explanation: The except block allows you to handle the errors.


Next Topic#





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA