PPS MCQs Unit 1-4
PPS MCQs Unit 1-4
Sr. Correct
Question Option1 Option2 Option3 Option4
No. Option
What is the maximum possible length of an
1 32 8 16 None of these these None of these
identifier?
Guido van
2 Who developed the Python language? Guido van Rossum Niene Stom Zim Den Wick van Rossum
Rossum
3 In which year Python language developed? 1980 1995 1981 1989 1980
4 In which language Python is written? PHP English C All of the above C
Which one of the following is the correct
5 .py .python .p None of these these .py
extension of the Python file?
In which year was the Python 3.0 version
6 2000 2008 2010 2005 2008
developed?
What do we use to define a block of code in
7 Brackets Key Indentation d. None of these Indentation
Python language?
Which character is used in Python to make a
8 // / # ! #
single line comment?
stepwise
Top down design strategy is also known as: stepwise refinement output module input module none of above
refinement
10 string is collection of character numbers operators none of above character
infix
11 Types of expressions are infix expression outfix expression postfix expression a and c
expression
analysis and analysis and
12 A design is an intermediate sep between coding and testing testing and maintenance none of above
coding coding
13 How many types of problems in Python 1 2 3 4 2
Which of the following declarations is
14 __x = 3 _x=2 __xyz__ = 5 None of these None of these
incorrect?
Which of the following is not a keyword in
15 raise val try with val
Python language?
Which of the following operators is the correct
16 a**b a^b a^^b a^*b a**b
option for power(ab)?
Content:
Decision Control Statements: Decision control statements, Selection/conditional branching
Statements: if, if-else, nested if, if-elif-else statements. Basic loop Structures/Iterative statements:
while loop, for loop, selecting appropriate loop. Nested loops, The break, continue, pass, else
statement used with loops. Other data types- Tuples, Lists and Dictionary.
A. for loop
B. while loop
C. do-while loop
D. None of the above
Answer: C
list1 = [3 , 2 , 5 , 6 , 0 , 7, 9]
sum = 0
sum1 = 0
for elem in list1:
if (elem % 2 == 0):
sum = sum + elem
continue
if (elem % 3 == 0):
sum1 = sum1 + elem
print(sum , end=" ")
print(sum1)
A. 8 9
B. 8 3
C. 2 3
D. 8 12
Answer: D
A. if a>=2 :
B. if (a >= 2)
C. if (a => 22)
D. if a >= 22
Answer: A
A. else if
B. elseif
C. elif
D. None of the above
Answer: C
A. Yes
B. No
C. if/else not used in python
D. None of the above
Answer: A
A. pq
B. rs
C. pqrs
D. pq12
Answer: A
A. if a = b:
B. if a == b:
C. if a === c:
D. if a == b
Answer: B
A. True
B. False
C. Python has switch statement but we cannot use it.
D. None of the above
Answer: B
A. 2
B. 6 5 2
C. 3
D. 5 2
Answer: A
str1="hello"
c=0
for x in str1:
if(x!="l"):
c=c+1
else:
pass
print(c)
A. 2
B. 0
C. 4
D. 3
Answer: D
15. Which of the following Python code will give different output from the others?
A. for i in range(0,5):
print(i)
B. for j in [0,1,2,3,4]:
print(j)
C. for k in [0,1,2,3,4,5]:
print(k)
D. for l in range(0,5,1):
print(l)
Answer: C
A. rnpn ea
B. rnpn ear
C. rnp ea
D. rnp ear
Answer: B
19. Which of the following sequences would be generated bt the given line of code?
range (5, 0, -2)
A. 5 4 3 2 1 0 -1
B. 5 4 3 2 1 0
C. 5 3 1
D. None of the above
Answer: C
A. indefinite
B. discriminant
C. definite
D. indeterminate
Answer: A
21. When does the else statement written after loop executes?
A. a b c d e f
B. abcdef
C. i i i i i.....
D. No Output
Answer: D
A. abcd
B. 0 1 2 3
C. 1 2 3 4
D. a b c d
Answer: B
A. 12
B. 1 2
C. Error
D. None of the above
Answer: C
A. No output
B. ice cream
C. "ice cream is tasty!"
D. None of the above
Answer: C
A. prrrr
B. ruf
C. prrrrruff
D. None of the above
Answer: B
A. fan
B. cream
C. glass
D. None of the above
Answer: C
A. ireland
B. maria
C. usa
D. colombia
Answer: D
A. error
B. cardio
C. No output
D. None of the above
Answer: C
A. 201
B. 101201
C. 101
D. error
Answer: C
A. BMW
B. Ford
C. Nissan
D. Audi
Answer: B
A. huh?
B. 0 is falsy
C. huh? 0 is falsy
D. No Output
Answer: B
if 4 + 5 == 10:
print("TRUE")
else:
print("FALSE")
print("TRUE")
x=3
if (x > 2):
x = x * 2;
if (x > 4):
x = 0;
print(x)
A. x will always equal 0 after this code executes for any value of x
B. if x is greater than 2, the value in x will be doubled after this code executes
C. if x is greater than 2, x will equal 0 after this code executes
D. None of the Above
Answer: C
A. $3.45
B. $3.11
C. $3.105
D. $3.10
Answer: C
A. (num1 = num2)
B. (num1 = num2) OR (num1 ≠ num2)
C. (num1 = num2) AND (num1<0)
D. (num1 = num2) AND (num2>0)
Answer: D
A. [‘AB’, ‘CD’]
B. [‘ab’, ‘cd’, ‘AB’, ‘CD’]
C. [‘ab’, ‘cd’]
D. none of the mentioned
Answer: D
A. 1 2
B. 1 2 3
C. error
D. none of the mentioned
Answer: C
A. 1 2 3 4 5 6
B. 1 2 3 4 5 6 7
C. error
D. none of the mentioned
Answer: A
A. True
B. False
C. None
D. none of the mentioned
Answer: D
A. 0 1 2 3 0
B. 0 1 2 0
C. 0 1 2
D. error
Answer: B
A. no output
B. i i i i i i …
C. a a a a a a …
D. a b c d e f
Answer: B
A. i i i i i i
B. a a a a a a
C. a a a a a
D. none of the mentioned
Answer: B
A. a a a a a a
B. a
C. no output
D. error
Answer: B
A. a a a a a a
B. a
C. no output
D. error
Answer: C
A. a B C D
B. a b c d
C. A B C D
D. error
Answer: B
A. a b c d
B. A B C D
C. a B C D
D. error
Answer: B
A. a b c d
B. 0 1 2 3
C. error
D. 1 2 3 4
Answer: B
a)
Hello World!
Hello World!
b)
'Hello World!'
'Hello World!'
c)
Hello
Hello
d) None of the mentioned
a)
6
15
b)
6
100
c)
123
12345
d) None of the mentioned
Answer: a
21. Python supports the creation of anonymous functions at runtime, using a construct
called __________
a) lambda
b) pi
c) anonymous
d) none of the mentioned
Answer: a
22. What will be the output of the following Python code?
1. y = 6
2. z = lambda x: x * y
3. print z(8
a) 48
b) 14
c) 64
d) None of the mentioned
a) 432
b) 24000
c) 430
a) 9997
b) 9999
c) 9996
d) None of the mentioned
Answer: c
31. What is a variable defined outside a function referred to as?
a) A static variable
b) A global variable
c) A local variable
d) An automatic variable
Answer: b
32. What is a variable defined inside a function referred to as?
a) A global variable
b) A volatile variable
c) A local variable
d) An automatic variable
Answer: c
s = "python rocks"
print(s[1] * s.index("n"))
A. yyyyy
B. 55555
C. n
D. Error, you cannot combine all those things together.
Ans-D
Ans-A
Ans-A
s1 = "HEY"
s2 = s1.lower()
s3 = s2.capitalize()
A. Hey
B. hey
C. HEY
D. HEy
Mali = 5
print("Mali" + " is " + str(Mali))
A. Mali is Mali
B. Mali is 5
C. 5 is Mali
D. 5 is 5
Ans- B
s = "python rocks"
print(s[3])
A. t
B. h
C. c
D. Error, you cannot use the [ ] operator with a string.
Ans- B
s = "python rocks"
print(s[2] + s[-5])
A. tr
B. ps
C. nn
D. Error, you cannot use the [ ] operator with the + operator.
Ans-A
s = "python rocks"
print(len(s))
A. 11
B. 12
C. 10
D. 7
Ans-B
s = "Rose"
s[1] = "i"
print(s)
A. Rose
B. Rise
C. Error
D. Rsoe
Ans-C
s = "ball"
r = ""
for item in s:
r = item.upper() + r
Print(r)
A. Ball
B. BALL
C. LLAB
D. LAB
Ans-C
s = "python rocks"
print(s[7:11] * 3)
A. rockrockrock
B. rock rock rock
C. rocksrocksrocks
D. Error, you cannot use repetition with slicing.
Ans-A
A. True
B. False
Ans-B
A. str objects
B. Incorrect
C. changeable
D. Immutable
Ans-C
>>>"a"+"bc"
a) a
b) bc
c) bca
d) abc
Answer: d
Explanation: + operator is concatenation operator.
>>>"abcd"[2:]
a) a
b) ab
c) cd
d) dc
Answer: c
Answer: b
Explanation: Execute in shell and check.
a) olleh
b) hello
c) h
d) o
Answer: d
Explanation: -1 corresponds to the last index.
Answer: c
Explanation: + is used to concatenate and * is used to multiply strings.
>>>print (r"\nhello")
Answer: b
Explanation: When prefixed with the letter ‘r’ or ‘R’ a string literal becomes a raw
string and the escape sequences such as \n are not converted.
>>>print('new' 'line')
a) Error
b) Output equivalent to print ‘new\nline’
c) newline
d) new line
Answer: c
Explanation: String literal separated by whitespace are allowed. They are
concatenated.
>>> print('x\97\x98')
a) Error
b)
97
98
c) x\97
d) \x97\x98
Answer: c
Explanation: \x is an escape sequence that means the following 2 digits are a
hexadecimal number encoding a character.
>>>str1="helloworld"
>>>str1[::-1]
a) dlrowolleh
b) hello
c) world
d) helloworld
Answer: a
Explanation: Execute in shell to verify.
Answer: d
Explanation: 0xA and 0xB and 0xC are hexadecimal integer literals representing the
decimal values 10, 11 and 12 respectively. There sum is 33.
str1="6/4"
print("str1")
A. 1
B. 6/4
C. 1.5
D. str1
Ans : D
Explanation: Since in print statement, str1 is written inside double quotes so it
will simply print str1 directly.
str1="python"
A. print(str1[2])
B. str1[1]="x"
C. print(str1[0:9])
D. Both (b) and (c)
Ans : B
Explanation: Strings are immutable. So,new values cannot be assigned at any
index position in a string
A. String is immutable.
B. capitalize() function in string is used to return a string by converting the whole
given string into uppercase.
C. lower() function in string is used to return a string by converting the whole given
string into lowercase.
D. None of these.
Ans : B
Explanation: capitalize() function in string gives the output by converting only the
first character of the string into uppercase and rest characters into
lowercase.However, upper() function is used to return the whole string into
uppercase.
str1="Information"
print(str1[2:8])
A. format
B. formatio
C. orma
D. ormat
Ans : A
Explanation: Concept of slicing is used in this question. In string slicing,the
output is the substring starting from the first given index position i.e 2 to one less
than the second given index position i.e.(8-1=7) of the given string str1. Hence,
the output will be "format".
str1="Aplication"
str2=str1.replace('a','A')
print(str2)
A. application
B. Application
C. ApplicAtion
D. applicAtion
Ans : C
Explanation: replace() function in string is used here to replace all the existing "a"
by "A" in the given string.
str1="poWer"
str1.upper()
print(str1)
A. POWER
B. Power
C. power
D. poWer
Ans : D
Explanation: str1.upper() returns the uppercase of whole string str1. However,it
doesnot change the string str1. So, output will be the original str1.
str1.find("save")
A. It returns the first index position of the first occurance of "save" in the given
string str1.
B. It returns the last index position of the last occurance of "save" in the given
string str1.
C. It returns the last index position of the first occurance of "save" in the given
string str1.
D. It returns the first index position of the first occurance of "save" in the given
string str1.
Ans : A
Explanation: It returns the first index position of the first occurance of "save" in
the given string str1.
list1=[0,2,5,1]
str1="7"
for i in list1:
str1=str1+i
print(str1)
A. 70251
B. 7
C. 15
D. Error
Ans : D
Explanation: list1 contains integers as its elements. Hence these cannot be
concatenated to string str1 by simple "+" operand. These should be converted to
string first by use of str() function,then only these will get concatenated.
If str1="John,Simon,Aryan"
A. print(str1[-7:-12])
B. print(str1[-11:-7])
C. print(str1[-11:-6])
D. print(str1[-7:-11])
Ans : C
Explanation: Slicing takes place at one index position less than the given second
index position of the string. So,second index position will be -7+1=-6.
str1="Stack of books"
print(len(str1))
A. 13
B. 14
C. 15
D. 16
Ans : B
Explanation: len() returns the length of the given string str1, including spaces and
considering " " as a single character.
print r"\nhello"
The output is
A. a new line and hello
B. \nhello
C. the letter r and then hello
D. Error
Ans: B
Answer: Option C
Explanation:
Cannot concantenate str and int objects.
print('ab'.isalpha())
A. True
B. False
C. None
D. Error
Answer: Option A
Explanation:
The string has only letters.
A - Hello World!
B-H
C - ello World!
Answer : B
Explanation
H is the correct answer.
B - [123, 'john'] * 2
C - Error
Answer : A
Explanation
It will print list two times. Output would be [123, 'john', 123, 'john'].
A - repr(x)
B - eval(str)
C - tuple(s)
D - list(s)
Answer : B
Explanation
eval(str) − Evaluates a string and returns an object.
A - unichr(x)
B - ord(x)
C - hex(x)
D - oct(x)
Answer : B
Explanation
ord(x) − Converts a single character to its integer value.
A - break
B - continue
C - pass
Answer : C
Explanation
pass statement − The pass statement in Python is used when a statement is
required syntactically but you do not want any command or code to execute.
A - isupper()
B - join(seq)
C - len(string)
D - ljust(width[, fillchar])
Answer : A
Explanation
isupper() − Returns true if string has at least 1 character and all characters are in
uppercase.
Q-42 : Which of the following function returns the min alphabetical character
from the string str?
A - lower()
B - lstrip()
C - max(str)
D - min(str)
Answer : D
Explanation
min(str) − Returns the min alphabetical character from the string str.
B - ['Hi!'] * 4
C - Error
Answer : A
Explanation
['Hi!', 'Hi!', 'Hi!', 'Hi!']
Q-44 : What is the following function removes last object from a list?
A - list.index(obj)
B - list.insert(index, obj)
C - list.pop(obj=list[-1])
D - list.remove(obj)
Answer : C
Explanation
list.pop(obj=list[-1]) − Removes and returns last object or obj from list.
Answer : B
2. How to output the string “May the odds favor you” in Python?
Answer : A
Answer : B
Answer : D
Answer : A
Answer : D
Answer : B
Answer : C
Python:
1
2str = "My name is Kevin"
3
A. str[11:16]
B. str(11:16)
Answer : A
10. Which of the following is the correct way to access a specific character. Let’s
say we need to access the character “K” from the following string in Python?
1
2str = "My name is Kevin"
3
A. str(11)
B. str[11]
C. str:9
D. None of the above
Answer : B
11. Which Python module is used to parse dates in almost any string format?
A. datetime module
B. time module
C. calendar module
D. dateutil module
Answer : D
12. Which of the following is the correct way to indicate Hexadecimal Notation in
Python?
A. str = ‘\62’
B. str = ’62’
C. str = “62”
D. str = ‘\x62’
Answer : D
13. To begin slicing from the end of the string, which of the following is used in
Python?
A. Indexing
B. Negative Indexing
C. Begin with 0th index
Answer : A
Answer : B
16. What is the correct way to get maximum value from Tuple in Python?
A. print (max(mytuple));
B. print (maximum(mytuple));
C. print (mytuple.max());
D. print (mytuple.maximum);
Answer : A
17. How to fetch and display only the keys of a Dictionary in Python?
A. print(mystock.keys())
B. print(mystock.key())
C. print(keys(mystock))
D. print(key(mystock))
Answer : A
19. How to access value for key “Price” in the following Python Dictionary:
1
2mystock = {
3"Product": "Earphone",
4"Price": 800,
5"Quantity": 50,
6"InStock" : "Yes"
7}
8
A. mystock[“Product”]
B. mystock(“Product”)
C. mystock[Product]
D. mystock(Product)
Answer : A
Answer : A
21. ___________ uses square brackets for comma-separated values in Python? Fill
Answer : A
Answer : A
“This is my website”?
A. str.find(“i”)
B. str.find(i)
C. str.index()
D. str.index(“i”)
Answer : D
Answer : B
25. Which of the following is the correcy way to access a specific element from a
Multi-Dimensional List?
A. list[row_size:column_size]
B. list[row_size][column_size]
C. list[(row_size)(column_size)]
D. None of the above
Answer : B
26. Which of the following Bitwise operators in Python shifts the left operand
value to the right, by the number of bits in the right operand. The rightmost bits
Answer : B
“mytuple”
A. print(mytuple[1:4])
B. print(mytuple[1 to 4])
C. print(mytuple[1-4])
D. print(mytuple[].slice[1:4])
Answer : A
Answer : B
Answer : A
Answer : C
31. How to delete an element in a Dictionary with a specific key. Let’s say we need
Answer : B
Answer : A
34. Which of the following is used to empty the Dictionary in Python? Let’s say
Answer : D
Answer : A
36. What is used in Python functions, if you have no idea about the number of
arguments to be passed?
A. Keyword Arguments
B. Default Arguments
C. Required Arguments
D. Arbitrary Arguments
Answer : D
Answer : A
38. In Python Functions, what is to be used to skip arguments or even pass them in
Answer : A
Answer : C
Answer : C
Answer : B
Answer : A
43. What is the correct way to get minimum value from a List in Python?
A. print (minimum(mylist));
B. print (min(mylist));
C. print (mylist.min());
D. print (mylist.minimum());
Answer : B
Answer : A
Answer : A
Answer : C
operator is to be used?
A. =
B. in operator
C. is operator
D. == (Answer)
Answer : D
48. What is the correct way to get minimum value from Tuple?
A. print (min(mytuple));
B. print (minimum(mytuple));
C. print (mytuple.min());
D. print (mytuple.minimum);
Answer : A
Answer : D
50. How to compare two objects and check whether they have same memory
locations?
A. is operator
B. in operator
C. **
D. Bitwise operators
Answer : A
Answer : A
Answer : B
Answer : A
Answer : C
55. Which of the following Bitwise operators sets each bit to 1, if only one of them
Answer : A
Answer : C
57. An example to correctly begin searching from the end range of index in
Answer : D
58. Which of the following Bitwise operators in Python shifts the left operand
value to the left, by the number of bits in the right operand. The leftmost bits
Answer : C
59. Can we update Tuples or any of its elements in Python after assignment?
A. Yes
B. No
Answer : A
Answer : B
Answer : B
Answer : A
Answer : B
Answer : B
Answer : A
Answer : A
Answer : A
68. How to fetch last element from a Python List with negative indexing?
A. print(“Last element = “,mylist[0])
B. print(“Last element = “,mylist[])
C. print(“Last element = “,mylist[-1])
D. None of the above
Answer : C
69. What is the correct way to get the length of a List in Python?
A. mylist.count()
B. count(mylist)
C. len(mylist)
D. length(mylist)
Answer : C
Answer : B