0% found this document useful (0 votes)
13 views

Python2 Edited

The document consists of a series of multiple-choice questions related to Python programming concepts, including syntax, functions, data types, and control structures. Each question is followed by a correct answer, indicating the expected knowledge for someone studying Python. The content is structured as a quiz format, covering various fundamental aspects of the Python language.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Python2 Edited

The document consists of a series of multiple-choice questions related to Python programming concepts, including syntax, functions, data types, and control structures. Each question is followed by a correct answer, indicating the expected knowledge for someone studying Python. The content is structured as a quiz format, covering various fundamental aspects of the Python language.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

1.

Comments are written in python using


a. // b. % c. # d. / Answer= b
# ‘str’ object does not support item assignment
Answer= c
8. Once the building process is successful and properly tested, it can be___
2. Pycharm is an ____for python (a) Interpreted (b) Deployed (c) Used (d) Translated
(a) IDE (b) Compiler (c) Hardware (d) Software
Answer = b
Answer= a
9. _________ operation can be used to delete particular items from a set.
3. Arguments are actual values passed into ____________ (a) Pop ( ) (b) discard ( ) (c) move ( ) (d) popitem( )
(a) Instructions (b) statements (c) loops (d) Parameters
Answer= b
Answer= d
10. List comprehension can be performed on only one list
4. Consider the loop control structure in programming. Which term describes a (a)True (b) False
loop that continues to repeat without a terminating condition? Answer= b
(a) Conditional (b) Sequence (c) Unlimited (d) Infinite #list comprehension can also be performed on More than one list.

Answer= d 11. Which of the following will run without Errors?


(a) Round () (b) round (7463.123, 2, 1) (c) round (6352. 898, 2, 5) (d) round
5. Remove () will delete particular value (45.8)
(a)from list (b) Remove List (c) None of the options (d) Delete methods from list
Answer=d
Answer – a #all other options will return error.

6. Statements with the same level of ____ belong to the same block of code 12. The first letter of a bool must be in capital Letter
(a) Indentation (b) Execution (c) Program (d) Parentheses (a) False (b) True

Answer= a Answer= b

7. What will be the output of the following Python code? 13. The ‘if’ statement is the ___ of conditional Programming in Python
>>> example= “snow world” (a) Mother (b) Background (c) Foundation (d) First
>>> example [3] = ‘s’
>>> print example Answer= c
(a) Snow world (b) Error (c) Snow (d) Snos World
14. Which of the conditional statements allows Multiple conditions easily Answer=a
(a) If-elif-else (b) If (c) If-else (d) Elif else
21. When the program doesn’t catch the exception, the interpreter prints_____
Answer=a (a) Nothing (b) A blank space (c) A stack Trace (d) Error

15. A list can be sliced Answer— c


(a) True (b) False
22. Python’s simple, easy to learn syntax emphasizes readability and therefore
Answer=a reduces the cost of programme maintenance.
(a) True (b) False
16. What will be the output of the following Python code?
23. Conditional statements control the ______ of the code and allow the computer
[‘F’, ‘T’] [bool (spam)] to think.
(a) No output (b) T (c) Error (d) F (a) Flow (b) style (c) part (d) rate

Answer= c Answer- a

17. Conditional ………………. Control the Flow of the code and allow the computer to 24. Which of the conditional Statements allow multiple conditions easily?
think. (a) Elif – else (b) If – else (c) If – elif – else (d) If
(a) Function (b) Structure (c) Statement (d) Operation
Answer- c
Answer= c
25. Which of the following is correct about tuples in python?
18. An elif condition requires an if condition But not an else condition. (a) It is mutable (b) Tuples are ordered (c) Tuples cannot be merged using the +
(a) True (b) False (c) Don’t know (d) None of the Above operators
(d) Indexing and slicing do not apply to tupples
Answer=a
Answer- b
19. The condition in a conditional statement Always returns a………. #these aren’t the exact options for this
(a) String (b) Integer (c) Boolean (d) None of the Above
26. Python module is a file with the ____ file extension that contains a valid python
Answer= c code
(a) All of the options (b) .module (c) .python (d) .py
20. When the interpreter discovers an error, it Raises an exception
(a) True (b) False Answer- d
27. _______ is used to add an element of a particular value in the dict.? 2 >>> str[:2]
(a)Append() (b) Legend() (c) Add() (d)Extend() 3 >>>
(a) Hello (b) ello (c) llo (d) He
Answer- a Answer- d

28. Which of the following identify a particular data type as a string? 33. Immediately after python installation, you can start using the program?
I. “ ” (a) True (b) False
II. ‘ ’ Answer- a
III. ‘,
IV. A text that ends in .py 34. Which of the following is not an advantage of using modules?
(a) Provides a means of reuse of program code
(a) 2 and 4 (b) 4 only (c) 1, 2 and 3 (d) 1and 2 (b) Provides a means of dividing up tasks
(c) Provides a means of reducing the Size of the program
Answer- d (d) Provides a means of testing individual parts of the program

29. ________ is the extent to which variables are accessible within a python Answer- c
program Explanation: The total size of the program remains the same regardless of
(a) Area (b) Scope (c) Jurisdiction (d) Lifetime whether modules are used or not. Modules simply divide the program.

Answer- b 35. What is the output of the following python Code?


#Where a variable is accessible and how long It exists depend on how it is L = [1, 0, 2, 0, “hello”, ‘’, [I]]
defined. We call the part of a program where a variable is accessible its scope, List (filter(bool, I))
and the duration for which the variable exists its lifetime. (a) Error
(b) {1, 0, 2, 0, “hello”, ‘’, [I]}
30. Python programming language is an object Oriented language (c) {1, 0, 2, “hello”, ‘’, [I]}
(a) False (b) True (d) {1, 0, 2, “hello”}

Answer- b Answer- a
#this code returns error because I is not
31. What will be the output of the following Python operation? 2**3
(a) 8 (b) 12 (c) 0 (d) 2
36. To use a module in another module, you must import it using an ______
Answer- a statement
(a) Import (b) external (c) go (d) another
32. What is the output of the following python Code
1 >>> str = “Hello” Answer- a
While I in x
If conditional statement is True
Print(I, end=””)
# execute expression1
Pass (a) All (b) abcdef (d) a b c d e (d) no Output
Else
Answer-d
# execute expression2 # “I” is not in “abcdef”
Pass
42. Which of the following is a valid for loop In python?
37. In the illustration above, it is necessary to specify the beginning of the if
statement’s code to be executed. For (n = 1 &πn**)
(a) True (b) None of the option (c) Don’t know (d) False For n in range(0.2)
For n in range(0,5)
Answer- a
For n in range(5)
38. In python, all negative numbers start with ______ symbol
(a) neg (b) minus (c) – (d) + Answer- c

Answer- c 43. The if statement executes a block of ________ when a condition is satisfied
(a) Logical (b) Statement (c) Program (d) Code
39. Each nested if statement requires further Indentation
(a) Don’t know (b) true (c) None of the option (d) false Answer-d

Answer- b 44. Choose the appropriate order for python Installation on Windows OS
I Download the latest release for Python installer
40. remove() will? II Open the Installer
(a) Delete particular value from the List III Scroll to the bottom and select the Executable file for either 32 bit and 64 Bit
(b) None of the option Iv Run the application
(c) Delete method from list
(d) Remove List (a) 1, 3, 4, 2 (b) 1, 3, 2, 4 (c) 1, 2, 3, 4 (d) 3, 4, 2, 1
Answer-a
Answer-c
41. What will be the output of the following Code?
X = “abcdef” 45. A list can be gotten from a range?
(a) True (b) false
I = “i”
Answer-a Answer-b

46. math.log() returns the ____ of a given Number 52. Which of the following looping structure works on a particular range in python?
(a) logarithm (b) exponent (c) inverse (d) Derivatives (a) Do while loop (b) While loop (c) For loop (d) Recursion

Answer-a Answer-b

47. The _____ keyword is required to import a module into another module in 53. ______ is used to return the factorial of a given number
python (a) Math log (b) Math factorial (c) Math print (d) Math fact
(a) Import (b) None of the option (c) From (d) Export
Answer- b
Answer- a
54. What is the Output of print list[1:3] if list = [‘abcd’, 786, 223, ‘john’, 70.2]?
48. To search an element in a tuple, use? (a) None of the option
(a) Within (b) In (c) from (d) not (b) [‘abcd’, 786, 223, ‘john’, 70.2]
(c) Abcd
Answer-b (d) [786, 223]

49. Which of the following isn’t true about Dictionary keys? Answer- d
(a) Keys must be immutable
(b) More than one keys isn’t allowed 55. What will be the output of the following Python code?
(c) Keys must be integers
(d) When duplicate keys encountered, the last assignment wins From math import factorial
Print(math.factorial(5))
Answer- c
# keys of a dictionary may be any data type that is immutable. You can use an 120
integer, Float, string, or Boolean as a dictionary key. Nothing is printed
50. Which of the following functions can be used to add elements to a list? (a) Error, method factorial doesn’t exist in math
(a) Pop() (b) Append() (c) Detach() (d) Attach() (b) Module
(c) Error, the statement should be:
Answer- b (d) Print(factorial(5))
51. Suppose list1 is {1, 5, 9}, what is Sum(list1)? Answer: b
(a) Error (b) 15 (c)9 (d) 1
56. Which of the following functions will not result in an error when no arguments
are Passed to it? 63. What is the correct extension of the Python File? A) .cpy b) .py c) python d)
(a) Float () (b) divmod() (c) all() (d) min() .pyth

Answer- a Answer- b

64. On December 3, 2008, which version of Python was developed? A. 1.0 b. 1.5 c.
57. The Python language was developed by? 2.0 d. 3.0
a. Dennis Ritchie b. Guido van Rossum c. Satoshi Nakamoto d. Niene Stom
Answer- d
Answer- b Version 3.0 of python was developed on December 3, 2008

58. The year in which Python Language Developed was? A. 1980 b. 1985 c. 1989 d. 65. If we do not define a return statement in a function, what will function return?
1992 a. Compiler error b. 0 c. None d. Runtime error

Answer- c Answer- c

59. The keyword used for function is? a. Function b. Def c. define d. Fun 66. Define a recursive function?
(a) A function that calls itself
Answer- b (b) A function that calls other functions
(c) a function that returns null
60. Which of the following items are present in the header of the function? A. List (d) None of these
of Parameters
b. Name of the function c. both (a) and (b) d. None of these Answer – a

Answer- c 67. Which of the following has the highest precedence in the expression in python?
(a) Exponential (b) Addition (c) Multiplication (d) Parenthesis
61. If we define a function inside a class, what will be called? A. Variables b. Class c. Answer- d
function d. Method
68. Which one of these is floor division in Python?
Answer- d
(a) /
62. The Python language is written in which Language? (a) C language (b) English (b) //
(c) Danish (d) Kotlin (c)%
(d) None of the mentioned
Answer- a
Answer- b
73. Which of the following operators has its associativity from right to left in
69. What does ~~~~~~5 evaluate to? Python?
(a) +5 (a) +
(b)-11 (b) //
(c) +11 (c) %
(d)-5 (d) **

answer- a Answer- d

70. What does ~4 evaluate to? 74. What does 3 ^ 4 evaluate to?
(a)-5 (a) 81 (b) 12 (c) 0.75 (D) 7
(b)-4
(c)-3 Answer- d (7)
(d)+3
75. What is the result of round (0.5)- round(-0.5)?
answer- a (a) 1.0 (b) 2.0 (c) 0.0 (d) value depends on Python version

71. Which of the following is not a complex Number? Answer- d


(a) K= 2+ 3j
(b) K= complex (2, 3) 76. Which of the following is incorrect?
(c) K=2 + 3i (a) Float(‘inf’)
(d) K= 2+ 3J (b) Float(‘nan’)
(c) Float(‘56’ + ‘78’)
Answer- c (d) Float(‘12+34’)
Letter i is not used in complex numbers.
Answer- d
72. What will be the value of x in the following Python expression? #This returns value error because it can’t convert string the float.

X = int(43.55+2/2) 77. What is the value of the following Expression?


(a) 43 Float(22//3+3/3)
(b) 44
(c) 22 (a) 8 (b) 8.0 (c) 8.3 (d) 8.33
(d) 23 Answer- b

Answer-b 78. What is the value of the following expression?


8/4/2, 8/(4/2) (a) True (b) False

(a) (1.0, 4.0) Answer- b


(b) (1.0, 1.0) 2**2**3= 256 while (2**2)**3 =64
(c) (4.0. 1.0)
(d) (4.0, 4.0) 83. What will be the value of the following Python expression?
4+2**5//10
Answer- a (a) 3
(b) 7
79. What are the values of the following python expressions? (c) 77
2**(3**2) (d) 0
(2**3)**2
2**3**2 Answer – b
(a) 64,512, 64 2**5 == 32, 32//10==3;
(b) 64, 64, 64 4+3==7
(c) 512, 512, 512
(d) 512, 64, 512 84. Which among the following list of operators has the highest precedence?
+,-, **,%,/, <<, >>,|
Answer- d (a) <<,>>
(b) **
80. The value of the expressions 4/(3*(2-1)) and 4/3*(2-1) is the same ? (c)|
(d) %
(a) True (b) False
Answer- b

85. What will be the output of the following Python expression?


81. What will be the value of X in the following python expression? 24//6%3, 24//4//2
X = 2+9*((3*12)-8)/10
(a) 30.0 (a) (1,3)
(b) 30.8 (b) (0,3)
(c) 28.4 (c) (1,0)
(d) 27.2 (d) (3, 1)

Answer- d Answer- a

82. The expression 2**2**3 is evaluated as: (2**2)**3? 86. What will be the output of the following Python expression?
Print(4.00/(2.0+2.0))
Answer- (b) abcefd
(a) Error
(b) 1.0 91. What will be the output of the following Python code snippet?
(c) 1.00 Print(‘ab cd-ef’.title())
(d) 1
(a) ab cd-ef
Answer- b (b) ab Cd-ef
(c) ab Cd-Ef
87. What is the use of “a” in file handling? (d) None of the mentioned
(a) Read
(b) Write Answer- (c)Ab Cd-Ef
(c) Append
(d) None of the mentioned 92. What is the output of this? Print(‘Ab!2’.swapcase())
(a) AB!@
Answer- c Append (b)Ab12
(c) aB!2
88. What is the output? (d) aB1@
>>”a”+”bc”
Answer- (c) aB!2
(a) a (b) bc (c) bca (d) abc
93. What will be the output of the following Python?
Answer- (d) abc Print ‘abef.replace(cd’, ’12))

89. Say s=”hello” what will be the return value of type(s)? (a) abef
(a) int (b) bool (c)str (d) String (b) 12
(c) error
Answer- (c) str (d) none of the mentioned

90. What will be the output of the following Python code snippet? Answer-a) abef
Print(abcefd’.replace(‘cd’, ‘12’))
94. Which of the following isn’t true about dictionary keys?
(a) ab1ef2
a) More than one key isn’t allowed
(b) abcefd
b) Keys must be immutable
(c) ab1efd
c) Keys must be integers
(d) ab12ed2
d) When duplicate keys encountered, the last assignment wins
102. To print multiple things in a single print command, they are separated
Answer: c using____
Explanation: Keys of a dictionary may be any data type that is immutable. (a) Commas (b) Dots (c) Quotation marks (d) Semicolon
Answer=a
95. A is a dictionary with some key-value pairs, what does a.popitem() do?
(a) Removes an arbitrary element
(b) Removes all the key-value pairs 103. Conditional statements control the…………of the code and allow the Computer
(c) Removes the key-value pair for the key given as an argument to think.
(d) Invalid method for dictionary (a) Code (b) Flow (c) Line (d) Sequence

Answer: a Answer— b (Flow)


Explanation: The method popitem() removes a random key-value pair.
104. Docstrings are encased in _____ (a) Hashtags (b) Double quotes (c) Triple
Quotes (d) None of the options
100. Nction in python? Answer— c
(a) seed()
(b) sqrt() 105. Docstrings are alternatives to multi-line Comments
(c) factorial() (a) True (b) False
(d) print() Answer—a

Answer: d 106. A list cannot be sliced? (a) True (b) False


Explanation: The function seed is a function which is present in the random Answer= b
module. The functions sqrt and factorial are a part of the math module. The
print function is a built-in function which prints a value directly to the system
output 107. What is the output of the following nested Loop?
Number = {“10”, “20”}
101. What is the maximum possible length of an identifier in Python?
(a) 79 characters Items = {“Chair”, “Table”}
(b) 31 characters
For x in numbers
(c) 63 characters
(d) none of the mentioned For y in items
Print (x, y, end=””)
Answer: d
Explanation: Identifiers can be of any length (a) 10 Chairs 10 Tables (b) 20 Chairs 20 Tables (c) 20 Chairs 20 Tables (d) 10
chairs 10 Tables

Answer- b
(a) AND (b) OR (c) NOT (d) XOR
108. Which of the following is an Invalid list Object? Answer – c
(a) All are valid
(b) [(1, 2), (3, 5)] 114. All Key words in python are in
(c) [10, 526, 3+7j, ‘Boy’] (a) Capitalized (b) Lower case (c) UPPER CASE (d) None of the mentioned
(d) List(“Hello”)
Answer - d
Answer- a
115. Who developed Python Programming Language?
109. PyCharm provide additional features like
a) Wick van Rossum
1. Specialized project views allowing quick switching between files
b) Rasmus Lerdor
2. Facilitates Web Development
c) Guido van Rossum
3. PyCharm is equipped with more than 1000 plugins, so Programmers can
d) Niene Stom
write their own
Plugins to extend its features.
(a) 1 and 3 (b) 1 and 2 (c) 1, 2, 3 (d) 1 only. Answer: c
Explanation: Python language is designed by a Dutch programmer Guido van
Answer- c Rossum in the Netherlands.

110. Which of the following represent a comment statement? 116. Which type of Programming does Python support?
(a) This is a comment (b) # This is a comment (c) # This is a comment # (d) This (a) object-oriented programming (b) structured programming (c) functional
is a comment # programming
Answer - b (d) all of the mentioned

111. How many times will it print the Statement? Answer: d


For in range(100) Explanation: Python is an interpreted programming language, which supports
object-oriented, structured, and functional programming.
Print(i)
(a) 99 (b) 101 (c) 100 (d) 0 117. Is Python case sensitive when dealing with identifiers?
Answer – a (a) no (b) yes (c) machine dependent (d) none of the mentioned

112. What is the output of 0.1 + 0.2 == 0.3? Answer: b


(a) Machine dependent (b) True (c) Error (d) false Explanation: Case is always significant while dealing with identifiers in python.

Answer- d 118. Which of the following is the correct extension of the Python file?
(a) .python (b) .pl (c) .py d) .p
113. Bitwise___ Gives 1 if either of the bits is 1 and 0 when both of the bits are 1? Answer: c
Explanation: ‘.py’ is the correct extension of the Python file. Python programs (c) Brackets
can be written in any text editor. To save these programs we need to save in (d) All of the mentioned
files with file extension ‘.py’.
119. Is Python code compiled or interpreted? Answer: a
(a) Python code is both compiled and interpreted Explanation: In Python, to define a block of code we use indentation.
(b) Python code is neither compiled nor interpreted Indentation refers to whitespaces at the beginning of the line.
(c) Python code is only compiled
(d) Python code is only interpreted 123. Which keyword is used for function in Python language?
(a) Function
Answer: a (b) def
Explanation: Many languages have been implemented using both compilers (c) Fun
and interpreters, including C, Pascal, and Python. (d) Define

120. All keywords in Python are in _________ Answer: b


(a) Capitalized Explanation: The def keyword is used to create, (or define) a function in
(b) lower case python.
(c) UPPER CASE
(d) None of the mentioned 124. Which of the following character is used to give single-line comments in
Python?
Answer: d (a) //
Explanation: True, False and None are capitalized while the others are in lower (b) #
case. (c) !
(d) /*
121. What will be the value of the following Python expression?
4+3%5 Answer: b
(a) 7 Explanation: To write single-line comments in Python use the Hash character
(b) 2 (#) at the beginning of the line. It is also called number sign or pound sign. To
(c) 4 write multi-line comments, close the text between triple quotes.
(d) 1 Example: “”” comment
text “””
Answer: a
Explanation: The order of precedence is: %, +. Hence the expression above, on 125. What will be the output of the following Python code?
simplification results in 4 + 3 = 7. Hence the result is 7. i=1
while True:
122. Which of the following is used to define a block of code in Python language? if i%3 == 0:
(a) Indentation break
(b) Key
print(i) (a) 4
(b) 2
i+=1 (c) 1
(a) 1 2 3 d) 8
(b) error
(c) 1 2 Answer: a
(d) none of the mentioned Explanation: The binary form of 1 is 0001. The expression x<<2 implies we are
performing bitwise left shift on x. This shift yields the value: 0100, which is the
Answer: b binary form of the number 4.
Explanation: SyntaxError, there shouldn’t be a space between + and = in +=.
129. What does pip stand for python?
126. Python supports the creation of anonymous functions at runtime, using a (a) Pip Installs Python
construct called __________ (b) Pip Installs Packages
a) pi (c) Preferred Installer Program
b) anonymous (d) All of the mentioned
c) lambda
d) none of the mentioned Answer: c
Explanation: pip is a package manager for python. Which is also called
Answer: c Preferred Installer Program.
Explanation: Python supports the creation of anonymous functions (i.e.
functions that are not bound to a name) at runtime, using a construct called 130. What are the values of the following Python expressions?
lambda. Lambda functions are restricted to a single expression. They can be 2**(3**2)
used wherever normal functions can be used. (2**3)**2
2**3**2
127. What is the order of precedence in python? (a) 512, 64, 512
(a) Exponential, Parentheses, Multiplication, Division, Addition, Subtraction (b) 512, 512, 512
(b) Exponential, Parentheses, Division, Multiplication, Addition, Subtraction (c) 64, 512, 64
(c) Parentheses, Exponential, Multiplication, Division, Subtraction, Addition (d) 64, 64, 64
(d) Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Answer: a
Answer: d Explanation: Expression 1 is evaluated as: 2**9, which is equal to 512.
Explanation: For order of precedence, just remember this PEMDAS (similar to Expression 2 is evaluated as 8**2, which is equal to 64. The last expression is
BODMAS). evaluated as 2**(3**2). This is because the associativity of ** operator is from
128. What will be the output of the following Python code snippet if x=1? right to left. Hence the result of the third expression is 512.
x<<2
131. Which of the following is the truncation division operator in Python? 134. Which of the following is the use of id() function in python?
(a) | (a) Every object doesn’t have a unique id
(b) // (b) Id returns the identity of the object
(c) / (c) All of the mentioned
(d) % (d) None of the mentioned

Answer: b Answer: b
Explanation: // is the operator for truncation division. It is called so because it Explanation: Each object in Python has a unique id. The id() function returns the
returns only the integer part of the quotient, truncating the decimal part. For object’s id.
example: 20//3 = 6.
135. What will be the output of the following Python function?
132. What will be the output of the following Python code? min(max(False,-3,-4), 2,7)
l=[1, 0, 2, 0, 'hello', '', []] (a) -4
list(filter(bool, l)) (b) -3
(a) [1, 0, 2, ‘hello’, ”, []] (c) 2
(b) Error (d) False
(c) [1, 2, ‘hello’]
(d) [1, 0, 2, 0, ‘hello’, ”, []] Answer: d
Explanation: The function max() is being used to find the maximum value from
Answer: c among -3, -4 and false. Since false amounts to the value zero, hence we are left
Explanation: The code shown above returns a new list containing only those with min(0, 2, 7) Hence the output is 0 (false).
elements of the list l which do not amount to zero. Hence the output is: [1, 2,
‘hello’]. 136. Which of the following is not a core data type in Python programming?
(a) Tuples
133. Which of the following functions is a built-in function in python? (b) Lists
(a) factorial() (c) Class
(b) print() (d) Dictionary
(c) seed()
(d) sqrt() Answer: c
Explanation: Class is a user-defined data type.
Answer: b
Explanation: The function seed is a function which is present in the random 137. What will be the output of the following Python expression if x=56.236?
module. The functions sqrt and factorial are a part of the math module. The print("%.2f"%x)
print function is a built-in function which prints a value directly to the system (a) 56.236
output. (b) 56.23
(c) 56.0000
(d) 56.24
Answer: d
Answer: d Explanation: The instance of the string returned by upper() is being printed.
Explanation: The expression shown above rounds off the given number to the
number of decimal places specified. Since the expression given specifies 141. What is the order of namespaces in which Python looks for an identifier?
rounding off to two decimal places, the output of this expression will be 56.24. (a) Python first searches the built-in namespace, then the global namespace
Had the value been x=56.234 (last digit being any number less than 5), the and finally the local namespace
output would have been 56.23. (b) Python first searches the built-in namespace, then the local namespace and
138. Which of these is the definition for packages in Python? finally the global namespace
(a) A set of main modules (c) Python first searches the local namespace, then the global namespace and
(b) A folder of python modules finally the built-in namespace
(c) A number of files containing Python definitions and statements (d) Python first searches the global namespace, then the local namespace and
(d) A set of programs making use of Python modules finally the built-in namespace

Answer: b Answer: c
Explanation: A folder of python programs is called as a package of modules. Explanation: Python first searches for the local, then the global and finally the
built-in namespace.
139. What will be the output of the following Python function?
len(["hello",2, 4, 6]) 142. What will be the output of the following Python code snippet?
(a) Error for i in [1, 2, 3, 4][::-1]:
(b) 6 print (i)
(c) 4 (a) 4 3 2 1
(d) 3 (b) error
(c) 1 2 3 4
Answer: c (d) none of the mentioned
Explanation: The function len() returns the length of the number of elements in
the iterable. Therefore the output of the function shown above is 4. Answer: a
Explanation: [::-1] reverses the list.
140. What will be the output of the following Python code?
x = 'abcd' 143. What will be the output of the following Python statement?
for i in x: >>>"a"+"bc"
print(i.upper()) (a) bc
(a) a B C D (b) abc
(b) a b c d (c) a
(c) error (d) bca
(d) A B C D
Answer: b
Explanation: + operator is concatenation operator. 147. What will be the output of the following Python program?
z=set('abc')
144. Which one of the following is not a keyword in Python language? z.add('san')
(a) pass z.update(set(['p', 'q']))
(b) eval z
(c) assert (a) {‘a’, ‘c’, ‘c’, ‘p’, ‘q’, ‘s’, ‘a’, ‘n’}
(d) nonlocal (b) {‘abc’, ‘p’, ‘q’, ‘san’}
(c) {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
Answer: b (d) {‘a’, ‘b’, ‘c’, [‘p’, ‘q’], ‘san}
Explanation: eval can be used as a variable.
Answer: c
145. What will be the output of the following Python program? Explanation: The code shown first adds the element ‘san’ to the set z. The set z
def foo(x): is then updated and two more elements, namely, ‘p’ and ‘q’ are added to it.
x[0] = ['def'] Hence the output is: {‘a’, ‘b’, ‘c’, ‘p’, ‘q’, ‘san’}
x[1] = ['abc']
return id(x) 148. What arithmetic operators cannot be used with strings in Python?
q = ['abc', 'def'] (a) *
print(id(q) == foo(q)) (b) –
(a) Error (c) +
(b) None (d) All of the mentioned
(c) False
(d) True Answer: b
Explanation: + is used to concatenate and * is used to multiply strings.
Answer: d
Explanation: The same object is modified in the function. 149. What will be the output of the following Python code?
print("abc. DEF".capitalize())
146. Which module in the python standard library parses options received from the (a) Abc. def
command line? (b) abc. def
(a) getarg (c) Abc. Def
(b) getopt (d) ABC. DEF
(c) main
(d) os Answer: a
Explanation: The first letter of the string is converted to uppercase and the
Answer: b others are converted to lowercase.
Explanation: getopt parses options received from the command line.
150. Which of the following statements is used to create an empty set in Python? (d) list1.add(5)
(a) ( )
(b) [ ] Answer: c
(c) { } Explanation: We use the function append to add an element to the list.
(d) set() 153. What will be the output of the following Python code?
print('*', "abcde".center(6), '*', sep='')
Answer: d (a) * abcde *
Explanation: { } creates a dictionary not a set. Only set() creates an empty set. (b) *abcde *
(c) * abcde*
151. What will be the value of ‘result’ in following Python program? (d) * abcde *
list1 = [1,2,3,4]
list2 = [2,4,5,6] Answer: b
list3 = [2,6,7,8] Explanation: Padding is done towards the right-hand-side first when the final
result = list() string is of even length.
result.extend(i for i in list1 if i not in (list2+list3) and i not in result) 154. What will be the output of the following Python code?
result.extend(i for i in list2 if i not in (list1+list3) and i not in result) >>>list1 = [1, 3]
result.extend(i for i in list3 if i not in (list1+list2) and i not in result) >>>list2 = list1
(a) [1, 3, 5, 7, 8] >>>list1[0] = 4
(b) [1, 7, 8] >>>print(list2)
(c) [1, 2, 4, 7, 8] (a) [1, 4]
(d) error (b) [1, 3, 4]
(c) [4, 3]
Answer: a (d) [1, 3]
Explanation: Here, ‘result’ is a list which is extending three times. When first
time ‘extend’ function is called for ‘result’, the inner code generates a Answer: c
generator object, which is further used in ‘extend’ function. This generator Explanation: Lists should be copied by executing [:] operation.
object contains the values which are in ‘list1’ only (not in ‘list2’ and ‘list3’).
Same is happening in second and third call of ‘extend’ function in these 155. Which one of the following is the use of function in python?
generator object contains values only in ‘list2’ and ‘list3’ respectively. (a) Functions don’t provide better modularity for your application
So, ‘result’ variable will contain elements which are only in one list (not more (b) you can’t also create your own functions
than 1 list). (c) Functions are reusable pieces of programs
(d) All of the mentioned
152. To add a new element to a list we use which Python command?
(a) list1.addEnd(5) Answer: c
(b) list1.addLast(5) Explanation: Functions are reusable pieces of programs. They allow you to give
(c) list1.append(5)
a name to a block of statements, allowing you to run that block using the (c) 0 1 2
specified name anywhere in your program and any number of times. (d) none of the mentioned

156. Which of the following Python statements will result in the output: 6? Answer: c
A = [[1, 2, 3], Explanation: The else part is not executed if control breaks out of the loop.
[4, 5, 6],
[7, 8, 9]] 159. What will be the output of the following Python code?
(a) A[2][1] x = 'abcd'
(b) A[1][2] for i in range(len(x)):
(c) A[3][2] print(i)
(d) A[2][3] (a) error
(b) 1 2 3 4
Answer: b (c) a b c d
Explanation: The output that is required is 6, that is, row 2, item 3. This position (d) 0 1 2 3
is represented by the statement: A[1][2].
Answer: d
157. What is the maximum possible length of an identifier in Python? Explanation: i takes values 0, 1, 2 and 3.
(a) 79 characters 160. What are the two main types of functions in Python?
(b) 31 characters (a) System function
(c) 63 characters (b) Custom function
(d) none of the mentioned (c) Built-in function & User defined function
(d) User function
Answer: d
Explanation: Identifiers can be of any length. Answer: c
Explanation: Built-in functions and user defined ones. The built-in functions are
158. What will be the output of the following Python program? part of the Python language. Examples are: dir(), len() or abs(). The user defined
i=0 functions are functions created with the def keyword.
while i < 5:
print(i) 161. What will be the output of the following Python program?
i += 1 def addItem(listParam):
if i == 3: listParam += [1]
break
else: mylist = [1, 2, 3, 4]
print(0) addItem(mylist)
(a) error print(len(mylist))
(b) 0 1 2 0
(a) 5 (d) 4.5
(b) 8
(c) 2 Answer: c
(d) 1 Explanation: This is a built-in function which rounds a number to give precision
in decimal digits. In the above case, since the number of decimal places has not
Answer: a been specified, the decimal number is rounded off to a whole number. Hence
Explanation: + will append the element to the list. the output will be 5.

162. Which of the following is a Python tuple? 165. Which of the following is a feature of Python DocString?
(a) {1, 2, 3} (a) In Python all functions should have a docstring
(b) {} (b) Docstrings can be accessed by the __doc__ attribute on objects
(c) [1, 2, 3] (c) It provides a convenient way of associating documentation with Python
(d) (1, 2, 3) modules, functions, classes, and methods
(d) All of the mentioned
Answer: d
Explanation: Tuples are represented with round brackets. Answer: d
Explanation: Python has a nifty feature called documentation strings, usually
163. What will be the output of the following Python code snippet? referred to by its shorter name docstrings. DocStrings are an important tool
z=set('abc$de') that you should make use of since it helps to document the program better and
'a' in z makes it easier to understand.
(a) Error
(b) True 166. What is output of print(math.pow(3, 2))?
(c) False (a) 9.0
(d) No output (b) None
(c) 9
Answer: b (d) None of the mentioned
Explanation: The code shown above is used to check whether a particular item
is a part of a given set or not. Since ‘a’ is a part of the set z, the output is true. Answer: a
Note that this code would result in an error in the absence of the quotes. Explanation: math.pow() returns a floating point number.

164. What will be the output of the following Python expression? 167. Which of the following is the use of id() function in python?
round(4.576) (a) Every object in Python doesn’t have a unique id
(a) 4 (b) In Python Id function returns the identity of the object
(b) 4.6 (c) None of the mentioned
(c) 5 (d) All of the mentioned
Answer: b
Explanation: Each object in Python has a unique id. The id() function returns the
object’s id.

168. What will be the output of the following Python code?


x = [[0], [1]]
print((' '.join(list(map(str, x))),))
(a) 01
(b) [0] [1]
(c) (’01’)
(d) (‘[0] [1]’,)

Answer: d
Explanation: (element,) is not the same as element. It is a tuple with one item.
169. The process of pickling in Python includes ____________
(a) conversion of a Python object hierarchy into byte stream
(b) conversion of a datatable into a list
(c) conversion of a byte stream into Python object hierarchy
(d) conversion of a list into a datatable

Answer: a
Explanation: Pickling is the process of serializing a Python object, that is,
conversion of a Python object hierarchy into a byte stream. The reverse of this
process is known as unpickling.

You might also like