Output dari kode python berikut print .format 1112223334

Python Multiple Choice Questions and Answers on “Strings”.

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

print("Hello {name1} and {name2}".format(name1='foo', name2='bin'))

a) Hello foo and bin
b) Hello {name1} and {name2}
c) Error
d) Hello and
Answer: a
Clarification: The arguments are accessed by their names.

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

print("Hello {0!r} and {0!s}".format('foo', 'bin'))

a) Hello foo and foo
b) Hello ‘foo’ and foo
c) Hello foo and ‘bin’
d) Error
Answer: b
Clarification: !r causes the characters ‘ or ” to be printed as well.

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

print("Hello {0} and {1}".format(('foo', 'bin')))

a) Hello foo and bin
b) Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
c) Error
d) None of the mentioned
Answer: c
Clarification: IndexError, the tuple index is out of range.

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

print("Hello {0[0]} and {0[1]}".format(('foo', 'bin')))

a) Hello foo and bin
b) Hello (‘foo’, ‘bin’) and (‘foo’, ‘bin’)
c) Error
d) None of the mentioned
Answer: a
Clarification: The elements of the tuple are accessed by their indices.

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

print('The sum of {0} and {1} is {2}'.format(2, 10, 12))

a) The sum of 2 and 10 is 12
b) Error
c) The sum of 0 and 1 is 2
d) None of the mentioned
Answer: a
Clarification: The arguments passed to the function format can be integers also.

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

print('The sum of {0:b} and {1:x} is {2:o}'.format(2, 10, 12))

a) The sum of 2 and 10 is 12
b) The sum of 10 and a is 14
c) The sum of 10 and a is c
d) Error
Answer: b
Clarification: 2 is converted to binary, 10 to hexadecimal and 12 to octal.

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

print('{:,}'.format(1112223334))

a) 1,112,223,334
b) 111,222,333,4
c) 1112223334
d) Error
Answer: a
Clarification: A comma is added after every third digit from the right.

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

print('{:,}'.format('1112223334'))

a) 1,112,223,334
b) 111,222,333,4
c) 1112223334
d) Error
Answer: d
Clarification: An integer is expected.

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

print('{:$}'.format(1112223334))

a) 1,112,223,334
b) 111,222,333,4
c) 1112223334
d) Error
Answer: d
Clarification: $ is an invalid format code.

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

print('{:#}'.format(1112223334))

a) 1,112,223,334
b) 111,222,333,4
c) 1112223334
d) Error
Answer: c
Clarification: The number is printed as it is.

multiple choice questions on Python,

---- >> Below are the Related Posts of Above Questions :::

------>>[MOST IMPORTANT]<<------
  1. 250+ TOP MCQs on Python Strings and Answers
  2. 250+ TOP MCQs on Python Strings and Answers
  3. 250+ TOP MCQs on Python Strings and Answers
  4. 250+ TOP MCQs on Python Strings and Answers
  5. 250+ TOP MCQs on Python Strings and Answers
  6. 250+ TOP MCQs on Python Strings and Answers
  7. 250+ TOP MCQs on Python Strings and Answers
  8. 250+ TOP MCQs on Python Strings and Answers
  9. 250+ TOP MCQs on Python Strings and Answers
  10. 250+ TOP MCQs on Python Strings and Answers
  11. 250+ TOP MCQs on Python Strings and Answers
  12. 250+ TOP MCQs on Python Strings and Answers
  13. 250+ TOP MCQs on Python Mapping Functions and Answers
  14. 250+ TOP MCQs on Python While and For Loops and Answers
  15. 250+ TOP MCQs on Python Tuples and Answers
  16. 250+ TOP MCQs on Python While and For Loops and Answers
  17. 250+ TOP MCQs on Python Global vs Local Variables and Answers
  18. 250+ TOP MCQs on Python List Comprehension and Answers
  19. 250+ TOP MCQs on Python While and For Loops and Answers
  20. 250+ TOP MCQs on Python While and For Loops and Answers