Python MCQs on String: SET 9

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

print(‘{0:.2}’.format(1/3))

a) 0.333333

b) 0.33

c) 0.333333:.2

d) Error

Check Answer

Answer: b
2 specifies the precision.

 

 

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

print(‘{0:.2%}’.format(1/3))

a) 0.33

b) 0.33%

c) 33.33%

d) 33%

Check Answer

Answer: c
The symbol % is used to represent the result of an expression as a percentage.

 

 

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

print(‘ab12’.isalnum())

a) True

b) False

c) None

d) Error

Check Answer

Answer: a
The string has only letters and digits.

 

 

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

print(‘ab,12’.isalnum())

a) True

b) False

c) None

d) Error

Check Answer

 

Answer: b
The character , is not a letter or a digit.

 

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

print(‘ab’.isalpha())

a) True

b) False

c) None

d) Error

Check Answer

Answer: a
The string has only letters.

 

 

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

print(‘a B’.isalpha())

a) True

b) False

c) None

d) Error

Check Answer
Answer: b
Space is not a letter.

 

 

87. What will be the output of the following Python code snippet?

print(‘0xa’.isdigit())

a) True

b) False

c) None

d) Error

Check Answer

Answer: b
Hexadecimal digits aren’t considered as digits (a-f).

 

 

88. What will be the output of the following Python code snippet?

print(”.isdigit())

a) True

b) False

c) None

d) Error

Check Answer

Answer: b
If there are no characters then False is returned.

 

 

89.What will be the output of the following Python code snippet?

print(‘my_string’.isidentifier())

a) True

b) False

c) None

d) Error

Check Answer
Answer: a
It is a valid identifier.

 

 

90. What will be the output of the following Python code snippet?

print(‘__foo__’.isidentifier())

a) True

b) False

c) None

d) Error

Check Answer

Answer: a
It is a valid identifier.

 

 

Pages  1  2  3  4  5  6  7  8  9  10  11  12  13

 

 

Leave a Comment