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

python mcq

The document contains a series of multiple-choice questions and answers related to Python programming concepts, including identifiers, operators, data types, loops, and string manipulation. Each question is followed by four options, with the correct answer indicated. The content serves as a quiz or test format for assessing knowledge of Python programming.

Uploaded by

Chaitanya reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

python mcq

The document contains a series of multiple-choice questions and answers related to Python programming concepts, including identifiers, operators, data types, loops, and string manipulation. Each question is followed by four options, with the correct answer indicated. The content serves as a quiz or test format for assessing knowledge of Python programming.

Uploaded by

Chaitanya reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

1)The developer of Python is-

Bjarne Stroustrup Guido van Rossum


John Warner Backus John G. Kemeny and Thomas E. Kurtz
Answer : Correct Option is : (b)

2)A token in programing language refers to-

Smallest unit of a program A part of a program


A reserve word All of these
Answer : Correct Option is : (a)

3)Which of the following ststement regarding python is NOT True?

It is a cross plateform language It a open source software


It supports OOP It a paid software
Answer : Correct Option is : (d)

4)Pick the correct statement about Python.

It is both compiler and interpreter based


It is compiler based language
language
Neither compiler based not interpreter
It is interpreter based language
based language
Answer : Correct Option is : (c)

5)Python works in _______ mode(s)

interactive mode only script mode only


both interactive and script mode neither interactive mode nor script mode
Answer : Correct Option is : (c)

6)What is an identifier?

It is a name given by the user for a


It is a keyword
part of a program
It is constant It is a function
Answer : Correct Option is : (a)

7)Which one of the following is NOT an identifier forming rule in Python?

It must starts with an alphabet It may have any character in it


It should not be a reserve word or key
It can have digits except at the beginning
word
Answer : Correct Option is : (b)
8)Which one of the following is correct definition of reserve word or keyword?

The words which are used for storing the


Keywords are functions.
constants
The words which has special meaning Keywords are the identifiers in a
in the language. program
Answer : Correct Option is : (c)

9)Which one of the following is a keyword in python?

input eval
false None
Answer : Correct Option is : (d)

10)Which one of the following is NOT a keyword?

as While
with def
Answer : Correct Option is : (b)

11)Which one of the following is an identifier.

S.I. 1stNo
class _12
Answer : Correct Option is : (d)

12)Which one of the following is NOT an identifier?

MyNo No 1
Value My_result
Answer : Correct Option is : (b)

13)Which one of the following is a relational operator.

+ =>
<= not
Answer : Correct Option is : (c)

14)Which one of the following is a logical operator?

>= or
in %
Answer : Correct Option is : (b)

15)Which one of the following is a membership operator?


in and
== //
Answer : Correct Option is : (a)
16)Which one of the following is not an operator type in Python?

Membership operator Relational operator


Statistical operator Logical operator
Answer : Correct Option is : (c)

17)What is the output of 13%5

2.6 2
3 0.6
Answer : Correct Option is : (c)

18)What is the output of 7%10

0 7
0.7 Error
Answer : Correct Option is : (b)

19)What is the output of 12//7

0 5
1.7 1
Answer : Correct Option is : (d)

20)What is the output of 9//10

0 0.9
1 Error
Answer : Correct Option is : (a)

21)"123" is a_______

variable string
string literal integer literal
Answer : Correct Option is : (c)

22)A named stored location whose value can be manipulated is called________

constant variable
string value
Answer : Correct Option is : (b)
23)Which one of the following is a relational operator?

= ==
=> and
Answer : Correct Option is : (b)

24)Which one of the following is not a legal numeric type in python?

int float
decimal All of these
Answer : Correct Option is : (c)

25)What is the output of - not(5<=6 and 8>=3) ?

True False
0 1
Answer : Correct Option is : (b)

26)What is the output of - "23"+"24" ?

47 2324
'2324' Error
Answer : Correct Option is : (c)

27)What is the output of - "44"+55

99 4455
'4455' Error
Answer : Correct Option is : (d)

28)What does x = y = 7 mean ?

y is assigned to zero and x is assigned to


x is assigned to zero and y is assigned to 7
7
both are assigned to 7 Error
Answer : Correct Option is : (c)

29)What does x, y = 6, 7 mean?

y is assigned to 7 and x is assigned


x is assigned to 7 and y is assigned to 6
to 6
both x and y assigned to 6 both x and y assigned to 7
Answer : Correct Option is : (b)
30)What does x, y = 10 mean?

x is assigned to 10 and y is assigned to


both x and y assigned to 10
zero
y is assigned to 10 and x is assigned to
Error
zero
Answer : Correct Option is : (d)
31)Which one of the following is not a valid data type in Python?

Sequence List
Tuple None
Answer : Correct Option is : (a)

32)Which built in function in Python returns the unique number assigned to an object?

identity() ref()
reference() id()
Answer : Correct Option is : (d)

33)The _____ operator is used to check if two operands reference the same object
memory.

== is
id in
Answer : Correct Option is : (b)

34)For two variables a and b, the expression 'a is b' returns True if and only if -

id(a)==id(b) a==b
len(a)==len(b) all of these
Answer : Correct Option is : (a)

35)Which of the following is not an immutable data type in Python?

String Tuple
Dictionary Set
Answer : Correct Option is : (c)

36)A Python variable must be declared before it is assigned a value-

True False
Only in function Only in module
Answer : Correct Option is : (b)

37)A Python variable is assigned a value of one type, later assigned a value of different
type, it will yield -

Error Warining
None No error
Answer : Correct Option is : (d)

38)A variable in Python can be assigned with any type of values, it is called-

static typing mutability


dynamic typing immutability
Answer : Correct Option is : (c)

39)Is it safe to use '==' to determine if two objects of type float is equal or not?

Yes No
Yes for small number only Yes for big number only
Answer : Correct Option is : (b)

40)Which of the following operatos has the lowest precedence?

+ **
not %
Answer : Correct Option is : (a)

41)What will be the result of 10 or 0?

0 10
True False
Answer : Correct Option is : (b)

42)What will be the result of 0 or 20?

True False
0 20
Answer : Correct Option is : (d)

43)What will be the result of 10 and 0?

0 10
True False
Answer : Correct Option is : (a)

44)What will be the result of 10 and 5?

5 10
True False
Answer : Correct Option is : (a)

45)What will be the result of 'a' and 'b'?

True False
a b
Answer : Correct Option is : (d)
46)An empty or null statement in Python is ____

go pass
over None
Answer : Correct Option is : (b)

47)The order of statement executation in the form of top to bottom, is known as


_________ construct.

flow repeatation
selection sequence
Answer : Correct Option is : (d)

48)The construct that repeat a set of statements for a specific number of times.

selection sequence
repeatation None of these
Answer : Correct Option is : (c)

49)Which of the following statement will make a selection construct?

for while
if-else none of these
Answer : Correct Option is : (c)

50)Which one of the following will make a repeatation construct?

for if-else
both (a) and (b) none of these
Answer : Correct Option is : (a)

51)The statement that allows to choose statement to be executed based on a condition


is known as -

selection repeatation
sequence none of these
Answer : Correct Option is : (a)
52)Which one of the following is not a valid loop in Python?

for do-while
while none of these
Answer : Correct Option is : (b)

53)Which of the following statement will terminate the while loop?

continue break
pass go
Answer : Correct Option is : (b)

54)Which of the statement will terminate the current pass of a loop?

continue break
pass go
Answer : Correct Option is : (a)

55)Consider the following loop-


for i in range(-5):
print(i)
how many times the loop will execute

5 0
infinite times Error
Answer : Correct Option is : (b)

56)range (3) will yield an iterable sequence-

[] [0,1,2,3]
[0, 1, 2] [1, 2, 3]
Answer : Correct Option is : (c)

57)range (3) is equivalent to -

range(1, 3) range(0,3)
range(0,4) range(1,4)
Answer : Correct Option is : (b)

58)What will be the output of the following code?


for k in range(2,6, 2):
print(k)

2, 4, 6 2, 4
2 6
Answer : Correct Option is : (b)

59)What will be the output of the following code?


k=1
while(k<=6):
k*=2
print(k)

8 14
16 infinite loop
Answer : Correct Option is : (a)

60)What will be the value of k after executing the following loop?


for k in range(5):
break

5 1
0 none of these
Answer : Correct Option is : (c)
1)Positive index of a string starts from-

Last character First character


Second last character Second character
Answer : Correct Option is : (a)

62)Negative index of a string starts from-

Last character First character


second character No negative index
Answer : Correct Option is : (a)

63)Which one of the following is not a valid string operator?

+ *
/ in
Answer : Correct Option is : (c)

64)Which of the following function is used to count total number of characters in a


string?

count() len()
index() none of these
Answer : Correct Option is : (b)

65)Which of the following functions is used to count the frequency of a character?


len() index()
count() all of these
Answer : Correct Option is : (c)

66)Which of the following functions returns a list of words of the string?

find() partition()
split() index()
Answer : Correct Option is : (c)

67)Which of the following functions returns the string in all capital letter?

toupper() upper()
isupper() to-upper()
Answer : Correct Option is : (b)

68)Which of the following functions will convert the string I love python
programing to I Love Python Programing?

title() capitalize()
upper() istitle()
Answer : Correct Option is : (a)

69)Which of the following functions will returns a tuple having the string in 3 pieces?

split() partition()
upper() replace()
Answer : Correct Option is : (b)

70)Which of the following functions returns the character from ASCII code?

ord() char()
character() chr()
Answer : Correct Option is : (d)

71)The function that removes leading and trailing spaces is _____

lstrip() rstrip()
strip() all of these
Answer : Correct Option is : (c)

72)Which of the following will return last three characters of the string S?

S[3::] S[-3::]
S[::-3] S[:3:]
Answer : Correct Option is : (b)

73)What will be the output of the following code?


s='Hello'
print(s*2)

Hello2 HelloHe
HelloHello Error
Answer : Correct Option is : (c)

74)If a string contains letter and digit, then which function returns True?

isalpha() isdigit()
isalnum() none of these
Answer : Correct Option is : (c)

75)What will be the output of the following code?


s='This is Python'
d='123'
print(s.isdigit(), d.isalpha())

True True True False


False True False False
Answer : Correct Option is : (d)
76)Which of the following a list can contain?

float integer
list all of these
Answer : Correct Option is : (d)

77)Which one of the following will create an empty list?

list(0) list()
list(empty) all of these
Answer : Correct Option is : (b)

78)If L1=[1, 2] and L2=[11, 22] then which one of the following will be returned by
L1+L2?

Error [1, 11, 2, 22]


[11, 22, 1, 2] [1, 2, 11, 22]
Answer : Correct Option is : (d)

79)If L=[4, 6, 8] then what will be returned by L*2?

[8, 12, 16] [4, 6, 8, 2]


[4, 6, 8, 4, 6, 8] None of these
Answer : Correct Option is : (c)

80)A list S having 7 elements the which one of the following will return the last
element?

S[-1] S[7]
S[len(S)] All of these
Answer : Correct Option is : (a)

81)Which of the following command will create a list?

L=list() L=[ ]
L=list(range(3)) All of these
Answer : Correct Option is : (d)

82)Which of the following will reverse a list S having 5 elements?

S[::-1] S[5:1]
S[len(S):1] S[-1:5]
Answer : Correct Option is : (a)

83)If k=[1,2,3,4,5,6,7] then which one of the following will be returned by print(k[-4:-
1])?

[4, 5, 6, 7] [4, 5, 6]
[7, 6, 5, 4] [7, 6, 5]
Answer : Correct Option is : (b)

84)If K=[2, 4, 6, 8, 10, 12] then what will be returned by print(K[1::2])

[4, 6, 8] [2, 4, 6]
[4, 8, 12] [2, 6, 10]
Answer : Correct Option is : (c)

85)If A=[1, 2, 3, 4, 5, 6, 7, 8] then what will be the output of print(A[2:50])?

Error [8]
[7, 8] [3, 4, 5, 6, 7, 8]
Answer : Correct Option is : (d)

86)What will be the output of print(list('python'))?

['python'] ['p', 'y', 't', 'h', 'o', 'n']


['nohtyp'] list('python')
Answer : Correct Option is : (b)

87)Which of the following is not a list method?

pop() remove()
len() append()
Answer : Correct Option is : (c)

88)Which of the following methods adds an element at the end of a list?

pop() add()
append() insert()
Answer : Correct Option is : (c)

89)Which of the following methods is used to add more than one element at the end of
a list?

append() add()
insert() extend()
Answer : Correct Option is : (d)

90)Which of the following can delete an element from a list?

del pop()
remove() all of these
Answer : Correct Option is : (d)
91)Which one of the following will create a tuple?

T=(3)*3 T=(3,)*3
T[3]=(1, 2, 3) None of these
Answer : Correct Option is : (b)

92)Which one of the following is correct?

List is immutable but tuple is mutable Both list and tuple are immutable
Tuple is immutable but list is mutable Both tuple and list are mutable
Answer : Correct Option is : (c)

93)Which one of the following is correct?

Tuple can contain only string Tuple can contain only integer
Tuple can contain different types of
Tuple can contain only string and integer
elements
Answer : Correct Option is : (d)
94)Which one of the following will create a tuple with single element?

T=(4,) T=(5)
T=([5]) T=tuple(5)
Answer : Correct Option is : (a)

95)If T=() then what will be the output of print(len(T*2))?

Error 1
0 2
Answer : Correct Option is : (c)

96)Which one of the following is a correct declaration of a tuple?

T=['Karan', 'Kishor', 'Kavita', 'Krishna'] T=(['Karan', 'Kishor', 'Kavita', 'Krishna'])


T=('Karan', 'Kishor', 'Kavita',
T=(['Karan', 'Kishor', 'Kavita', 'Krishna')
'Krishna')
Answer : Correct Option is : (c)

97)If T=(2, 4, 6) then what is the output of print(T*3)?

(6, 12, 18) (2, 4, 6, 2, 4, 6, 2, 4, 6)


(2, 2, 2, 4, 4, 4, 6, 6, 6) Error
Answer : Correct Option is : (b)

98)What will be the output of the following code?


T=(1, 2, 3, 4, 5)
T.pop()
print(T)

(1, 2, 3, 4) (2, 3, 4, 5)
(1, 2, 3, 4, 5) Error
Answer : Correct Option is : (d)

99)If T=(2, 3, 4) then which one of the following will raise an error?

T.sort() sorted(T)
max(T) sum(T)
Answer : Correct Option is : (a)

100)What is the output of the following code?


T=(5)
T1=T*2
print(len(T1))

10 0
1 Error
Answer : Correct Option is : (d)

101)Predict the output of the following code.


T=(3,)
T1=T*4
print(len(T1))

0 3
4 Error
Answer : Correct Option is : (c)

102)If T=(1, 2, 3, 4, 5, 6,7) then what will be the output of print(t[5:-1])

Error (6,)
() (6, 7)
Answer : Correct Option is : (b)

103)If T=(1, 2, 3, 4, 5, 6,7) then what will be the output of print(t[:-1])

(1, 2, 3, 4, 5, 6) (1, 2, 3, 4, 5, 6, 7)
(7,) ()
Answer : Correct Option is : (a)

104)If T=(1, 2, 3, 4, 5, 6,7) then what will be the output of print(t[::-1])

(1, 2, 3, 4, 5, 6, 7) (7, 6, 5, 4, 3, 2, 1)
() (7,)
Answer : Correct Option is : (b)

105)If T=(1, 2, 3, 4, 5, 6,7) then which two of the following will give the same output.
i) print(T[0:7])
ii) print(T[0:6])
iii) print(T[:-1])
iv) print(T[0:-6])

(i) and (ii) (ii) and (iii)


(iii) and (iv) (i) and (iii)
Answer : Correct Option is : (d)
106)Dictionary is a set of _______ elements.

unordered ordered
sorted unsorted
Answer : Correct Option is : (a)

107)Dictionary is ______ type of data type.


mutable immutable
ordinary all of these
Answer : Correct Option is : (a)

108)Dictionary is also called _______

hash table mapping


associative array all of these
Answer : Correct Option is : (d)

109)Which of the following dictionary methods returns keys of the dictionary?

values() keys()
update() items()
Answer : Correct Option is : (b)

110)Which of the following dictionary methods creates a dictionary with given keys and
common values?

default() update()
fromkeys() values()
Answer : Correct Option is : (c)

111)Which of the following dictionary methods will add a key-value pair in the
dictionary only if it does not exist?

fromkeys() setdefault()
update() items()
Answer :

112)If no values are specified in fromkeys() method then which of the following values
are assigned to the keys?

0 1
null None
Answer : Correct Option is : (d)

113)Which of the following methos is used to join two dictionaries?

update() setdefault()
copy() join()
Answer : Correct Option is : (a)

114)Which of the following methods can be used to delete element from a dictionary?
pop() del
popitem() all of these
Answer : Correct Option is : (d)

115)Which of the methods of a dictionary will raise an error if the key is not there in the
dictionary

del pop()
popitem() all of these
Answer : Correct Option is : (d)

116)Which of the following statements is correct with respect to the given code?
d={'x' : 10, 'y' : 20}

a dictionary 'd' is created 'x' and 'y' are two keys of the dictionary
10 and 20 are two values of the dictionary all of these
Answer : Correct Option is : (d)

117)A dictionary is defined as below-


d={'a':10, 'b':20, 'c':30}
Then what will be printed by print('b' in d)

False True
Error None
Answer : Correct Option is : (b)

118)A dictionary is defined as below-


d={'a':10, 'b':20, 'c':30}
Then what will be printed by print(30 in d)

Error None
False True
Answer : Correct Option is : (c)

119)Keys of a dictionary must be of ______ type

integer string
mutable immutable
Answer : Correct Option is : (d)

120)What will be the output of the following code?


d={'apple':10, 'banana':20, 'orange':30}
print(d[0])

apple 10
Error None
Answer : Correct Option is : (c)

You might also like