Python MCQ

Download as pdf
Download as pdf
You are on page 1of 6
Python MCQ (Multi Choice Questions) Q What is the maximum possible length of an identifier? a. 16 b, 32 c. 64 d. None of these above Answer: (d) None of these above Explanation: The maximum possible length of an identifier is not defined in the python language. It can be of any number, Q. Who developed the Python language? a. ZimDen b. Guido van Rossum ©. Niene Stom d. Wick van Rossum Answer: (b) Guido van Rossum Explanation: Python language was developed by Guido van Rossum in the Netherlands. Q In which year was the Python language developed? a 1995 b. 1972 c. 1981 d. 1989 Answer: (d) 1989 Explanation: Python language was developed by Guido van Rossum in 1989. Q In which language is Python written? a. English b. PHP « C d. All of the above Answer: (b) C Explanation: Python is written in C programming language, and it is also called CPython. Q. Which one of the following is the correct extension of the Python file? PY b. python cP d. None of these the correct extension of the Python file. Q In which year was the Python 3.0 version developed? a 2008 b. 2000 c. 2010 d. 2005 Answer: (a) 2008 Explanation: Python 3.0 version was developed on December 3, 2008. yeepe Q. What do we use to define a block of code in Python language? a Key b. Brackets ¢. Indentation 4d. None of these Answer: (c) Indentation Explanation; Python uses indentation to define blocks of code. Indentations are simply spaces or tals used as an indicator that is part of the indent code child. As used in curly braces C, C++, and Java. Q Which character is used in Python to make a single line comment? a bo c # a! Answer: (c) # Explanation: Q Which of the following statements is correct regarding the object-oriented programming concept in Python’? a, Classes are real-world entities while objects are not real b. Objects are real-world entities while classes are not real c, Both objects and classes are real-world entities d. Allof the above “#" character is used in Python to make a single-line comment. Answer: (b) Objects are real-world entities while classes are not real Explanation: None Q. Which of the following statements is correct in this python code? ‘class Name: javajavaipoint = java 8. It will throw the error as multiple references to the same object is not possible b. id(name!) and id(name2) will have same value ¢. Both name! and name? will have reference to two different objects of class Name 4d. Allof the above Answer: (b) id(name! ) and id(name2) will have same value ‘name1" and "name2" refer ta the same object, so id(name!) and id(name2) will have ‘the same value, Q What is the method inside the class in python language? a Object, b. Function cc, Attribute: d. Argument Answer: (b) Function Explanation: Function is also known as the method. Q. Which of the following operators is the correct option for powertab)? a at b. ab ce. ahhh di at*b Answer: (b) a*b Explanation: The power operator in python is a**b, ic, 2**3=8, Q. Which of the following precedence order is correct in Python? 4. Parentheses, Exponential, Multiplication, Division, Addition, Subtraction, b. Multiplication, Division, Addition, Subtraction, Parentheses, Exponential ¢, Division, Multiplication, Addition, Subtraction, Parentheses, Exponential 4, Exponential, Parentheses, Multiplication, Division, Addition, Subtraction Answer: (a) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction Explanation: PEMDAS (similar to BODMAS). Q. Which one of the following has the same precedence level? a Division, Power, Multiplication, Addition and Subtraction b. Division and Multiplication ¢, Subtraction and Division d. Power and Division Answer: (b) Division and Multiplication ‘Explanation: None Q. Which one of the following has the highest precedence in the expression? a Division b. Subtraction cc. Power Parentheses Answer: (d) Parentheses Explanation: PEMDAS (similar to BODMAS). . Which of the following functions is a built-in function in python language’? a. ‘val() b. print ce. print() d. None of these Answer: (b) print() Explanation: The print() function is a built-in function in python language that prints a value directly to the system. Q. Study the following funetion: round(4.576) What will be the output of this function? a 4 bos c. 576 ds Answer: (d) 5 : The round function is a built-in function in the Python language that round-off the value (like 3.85 is 4), so the output of this function will be 5. Q Which of the following is correctly evaluated for this function? pow(x.y.z) a (xy) /z b. (&/y)#z eC) % dd @&/y/2 Answer: (c) (x**y) % 2 ‘Explanation; None Q. Study the following function: all((2,4,0,6)) ‘What will be the output of this function? a False b. Tre 0 d. Invalid code Answer: (a) False ‘Explanation: If any element is zero, it returns a false value, and if all elements are non-zero, it returns true value, Hence, the output of this “all({2,4,0,6])" function will be false. Q. Study the following program: x=1 while True: ifx%5 break rint(x) x+el ‘What will be the output of this code? a error b 21 e031 d. None of these Answer: (a) error Explanation: Syntax error, there should not be a space between + and =, Q. Which one of the following syntaxes is the correct syntax to read from a simple text file stored in javatxt’ Infile Infile Infile Infile Answer: (a) Infile = open(’c:\scores.tx ‘Explanation: None wRYNe DURWIS BADD EUNE Q. Study the following program: isk while True: if i963 break print(i) Which of the following is the correct output of this program? a 123 b. 321 c. 12 Invalid syntax Answer: (d) Invalid syntax Explanation: Invalid syntax, because this declaration ( ) is wrong. Q. Study the following program: a=1 while True: ifa% 7= break print(a) ats Which of the following is correct output of this program? a. 12345 b. 123456 ec. 1234567 d. Invalid syntax Answer: (b) 123.456 Explanation: None Q. Study the following program: i=0 while i < 5: print(i) its! ifi break else: print(0) What will be the output of this statement? a 123 b. 0123 . O12 d 321 Answers (¢)0 12 Explanation: None Study the following program: = (0,1,2) for ind: prima) ‘What will be the output ofthis statement? a 40.1.2) (0,1,2} (0, 1,2) b 012 ©. Syntx_Eor d._ None ofthese shove Answer: (b) 0112 Explanation: None Q, Which ofthe following option is not a core datatype in the python language? a Dictionary b. Lists ce. Class Alot the above Answer: (c) Class Explanation: Classis not a core datatype because it user-defined data type Q. What error will occur when you execute the following code? MANGO = APPLE a. NameErvor 1b. SyntaxExror ce. TypeEror 4d. ValueError Answer: (a) NamaEror Explanation: Mango is not defined hence the name ero . Study the following program: def example(a) aa=as'T aa=atl >>>examplo("javatpoint”) ‘What will be the output ofthis statement? a. hello2hello2 b. hello? ‘e. Cannot perform mathematical operation on strings

You might also like