Professional Documents
Culture Documents
12cs-Term-1 Chapterwise MCQ
12cs-Term-1 Chapterwise MCQ
// comments // .pyt
/ comments / .py
''' comments ''' Correct answer
/# comments #/ .py
Correct answer 11.In Python, a syntax error is detected by the
''' comments ''' ________ at _________.
5. What does the expression string1 + string2 do? compiler/at compile time
Repeats string1 string2 times (string2 must be in interpreter/at runtime
numeric format). compiler/at runtime
1
Page
x,y,z = 1, 2, 3 100
x_y_z = 1,000,000 49.What is the output of the following code?
a = 15 % 3 5
All of the mentioned Correct answer
View Answer A. 4
Page
Answer : C B. 4.0
Explanation: The objects that operators act on are C. 0
03. Which one of the following is the correct way 07. Which of the following is not a valid variable
of declaring and initializing a name in Python?
Answer : D B. Tuple
Page
30. What does ~4 evaluate to? Explanation: Identifiers can be of any length.
Page
d) 1 d) Class
Page
Answer: c Answer: d
Explanation: First this expression will solve 1**3 Explanation: Class is a user defined data type.
the following operation to be performed. value we use what core data type.
Page
1. >>>x = 13 ? 2 a) list
objective is to make sure x has a integer value, b) tuple
hello-how-are-you c) -3
Page
5. What will be the value of x in the following which is equal to 512. Expression 2 is
Page
d) 27.2 float(4+int(2.39)%2)
Page
Answer: d a) 5.0
Explanation: The expression shown above is b) 5
10. The expression 2**2**3 is evaluates as: Explanation: When the value of x is equal to 8
(2**2)**3. (1000), then x>>2 (bitwise right shift)
d) int(‘1011’) a) True
Page
Answer: c b) False
Explanation: The expression int(1011,2) results in Answer: b
operand is returned. This is because each function returns the output False.
Page
is evaluated from left to right. The expression -6>=0 and -6<=10 returns the
Since the left operand is false, it is assumed that output False.
spaces before a given string ‘X’. Hence the output Explanation: The given number is -122. Here the
Page
for the code snippet shown above total number of digits (including the
will be 56 blank spaces before the string “san- negative sign) should be 6 according to the
4. What will be the output of the following Python values substituted for p and q in the
Page
i=5 break
Page
print(i) a) no output
Page
i += 1 b) i i i i i i …
if i == 3: c) a b c d e f
code? c) error
Page
2. What will be the output of the following Python 6. What will be the output of the following Python
Page
code? code?
d = {0: 'a', 1: 'b', 2: 'c'} d = {0: 'a', 1: 'b', 2: 'c'}
('wx', 'yz', '') 34.What will be the output of the following Python
Page
1pqrstv code?
40.What will be the output of the following Python x
52.To return the length of string s what command 58.What will be the output of the following Python
Page
do we execute? code?
s.__len__() 01
code? 4350
Page
PQRS pqrstv
Page
pqrs error
Correct answer none of the mentioned
x.__ADD(y) True
Page
pq+rs+tv Error
pq++++++++rs++++++++tv None of the mentioned
40 Error
Page
“10.3f”) (_ indicates space). 134. What will be the output of the following
Page
142. What will be the output of the following Page 135 of 391
Python code snippet? Counter({5: 3, 2: 2, 4: 2, 3: 1})
165. What will be the output of the following Removes an arbitrary element
Page
2 5
Page
204. What is list("pqrs")? 211. To remove string "red" from list1, use
['p', 'q', 'r', 's'] _______.
2234336334523445455 Option 2
2234334544523423345 Option 3
248. What will be the output of the following code? Page 166 of 391
Page
561 132
12 None
5 [14]
Page
5 False
Page
Error True
None of these above Page 174 of 391
g print(max(p))
289. What will be the output of the following print(len(p))
Ans. a. [‘w’, ‘e’, ‘l’, ‘c’, ‘o’, ‘m’, ‘e’] Q9. Write the output of the following code :
Q3. Write the output of the following code : L=list(“www.csiplearninghub.com”)
b. [1, 2, 3, 4, 3, 4, 5, 6] c. ValueError
Page
a. loop a. True
Page 194 of 391 b. False
a. [ ] Ans. c. [3, 2, 5, 7, 3, 6, 3]
Page
a. [1, 2, 3, 4, 5] L = [1, 2, 3, 4, 5]
Page
b. [1, 1, 1, 1, 1] a. [x ** 2 for x in L
c. [1, 0, 1, 0, 1 b. [x * 2 for x in L]
decimal values 10, 11 and 12 respectively. There Explanation: Execute in the shell and verify.
sum is 33. Page 207 of 391
b) 4 example\test.txt?
c) 3 a) print(“hello\example\test.txt”)
Answer: c Answer: c
Page
Explanation: Counts the number of times the Explanation: A bytes object is returned by encode.
substring ‘yy’ is present in the given 8. What is the default value of encoding in
d) [‘olleh’] operation?
Answer: a a) print(list1[0])
c) [1, 4] c) 2
Page
d) [1, 3, 4] d) Error
Answer: b Answer: c
b) 4 code?
Page
c) 5 1. def example(L):
d) 8 2. ''' (list) -> list
code? a[3][0]=95
Page
1. data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] a[1]=34
2. print(b)
print(lst) a.extend([45,67])
Page
a) [3, 7, 8, 6, 1, 2] print(a)
b) Syntax error a) [13, 56, 17, [87], 45, 67]
list1=[1,2,3] Answer: b
Page
are shifted forward by one index Explanation: The above piece of code basically
Page
due to the first for-loop and the item of index four prints the index of the largest element in
is printed again because of the the list.
Answer: b code?
Page
c) 33 d) Syntax error
Page
d) 12 Answer: c
Answer: c Explanation: Here (“Check”) is a string not a tuple
code? ((('check',),),)
>>> a=(0,1,2,3,4) c) ((‘check’,)’check’,)
Answer: b d) 4
Explanation: The values of a dictionary can be Answer: d
b) None print(a)
c) 3 Page 267 of 391
c) {4:3} code?
d) [(4, 3)] count={}
Page
Answer: d count[(1,2,4)] = 5
Explanation: The most_common() method returns count[(4,2,1)] = 7
>>> a >>> b
a) Dictionary comprehension doesn’t exist a) {‘a’: 1, ‘b’: 2, ‘c’: 3}
Page
even if the keys don’t exist in the satisfying the conditions given within the
dictionary. parenthesis and in an ascending order of the
d) Docstring s=[1,2,3]
Answer: d change(s)
modulename.identifier Answer: d
Answer: a Explanation: In the “from-import” form of import,
Page
Explanation: In the “import modulename” form of the imported identifiers (in this
import, the namespace of imported case factorial()) aren’t specified along with the
c) -3 c) error
d) -3.0 d) none of the mentioned
Page
Answer: d Answer: a
Explanation: The copysign function returns a float Explanation: The factorial of 4 is returned.
Answer: d a) 1
Explanation: There is some loss of accuracy when b) 2.0
Explanation: The code shown above displays the While random.randint(a,b) generates
incorrect syntax of the function an integer between ‘a’ and ‘b’, including ‘a’ and
Page
random.choice(). This functions takes its numeric ‘b’, the function random.uniform(a,b)
parameter in the form of a list. Hence generates a decimal value between ‘a’ and ‘b’.
10. What is the interval of the value generated by 14. What will be the output of the following Python
the function random.random(), assuming code?
Page
random.randrange(4)? a) 0
a) 0 b) 1
Page
b) 3 c) KeyError: 1
c) 2.3 d) none of the mentioned
instead of the position (which we have c) Docstrings can be accessed by the __doc__
been using all along) to specify the arguments to attribute on objects
Page
15. Which of the following is the use of id() function 4. print C2F(0)
in python? a)
Page
4. r = 0 c) 64
5. for i in args: d) None of the mentioned
Page
6. r += i Answer: a
7. return r Explanation: The lambda keyword creates an
27. What will be the output of the following Python Explanation: None.
code? 30. What will be the output of the following Python
Page
Explanation: The complex function returns 0j if both b) [(1, 2), (2, 3)]
of the arguments are omitted, that is, if c) [(0, 2), (1, 3)]
the second function adds 3 zeros after the given -12345.0 (5 blank spaces before the number) a
number. b) -12345.0 )
Page
Junk value 69. What will be the output of the following Python
Answer: a function?
Page
program itself. Therefore the length of 77. What will be the output of the following Python
sys.argv is one more than the number arguments. code?
return x b) list
for i in range(3): c) tuple
Answer: a print(x)
Explanation: The same object is modified in the x=+1
p = 10 def f2(a,b):
q = 20 global x
Explanation: The tell() method tells you the current method is called repeatedly. This method
position within the file; in other words, returns the next input line, or raises StopIteration
Page
the next read or write will occur at that many bytes when EOF is hit.
from the beginning of the file. Output:
objects are converted into byte streams and Explanation: The method flush() flushes the internal
written to text files. This process is called pickling. buffer. Python automatically flushes the
Page
The inverse operation, reading from a file files when closing them. But you may want to flush
and reconstructing objects is called deserializing or the data before closing any file.
a) Read d) writechar()
b) Write Answer: a
Page
“w” Opens a file for writing only. Overwrites the file a) fp.name
if the file exists. If the file does not b) fp.closed
a) writeline() c) f.readline()
b) writelines() d) f.readlines()
Page
b. unpickle b. False
c. pandas Ans. b. False
b. NotFoundError c. 0
c. FileNotFound d. All of the above
Page
c. pickle a. end
d. None of the above b. beginning
Page
Q64. Write the output of the following: Q70. Which of the following mode will open the file
>>> f = open("test.txt","w") in binary and read-only mode.
Page
Page 367 of 391 the following syntax. His friend told him
Q76. Ravi opened a file in a certain mode. After few advantages of the given syntax. Help him to
Page
opening the file, he forgot the mode. One identify the correct advantage.
interesting fact about that mode is ” If the file with open ("myfile.txt", "a") as file_object:
f.write("FileHandling") c. Fi
f.seek(0) d. No Output
d. unpickling a. 0
Ans. b. pickle b. 1
Page
d. readline( ) print(len(f.read()))
Ans. a. reader( ) a. 13
Page
C. print(len(f.read( ).split( ))) #f is file handle help her to complete the code.
d. None of the above ________ csv #Statement1
Page
cls = input(“Enter Class: “) Q149. Identify the correct statement for Statement
rec=[_________] #Statement3 2.(Refer Q148.)
Page
d.writerow(rec) a. read
ch=input(“Enter more record??(Y/N)”) b. reader( )
b. b_name f.read()
c. b_price f.read(all)
Page
open() sys.stdout.write("ABC")
dump pickle
162
Page