Python Formatting MCQs with Answers

Practice MCQs for Formatting

Explore reliable objective questions for Formatting tailored for learners. Utilizing these multiple-choice formats ensures thorough preparation and strengthens problem-solving speed for upcoming school assessments.

Access Formatting Questions and Solutions

Access the complete set of multiple-choice questions for Formatting below. This focused format allows students to isolate specific topics for thorough review and uninterrupted practice alongside official NCERT textbooks.

Question. What will be the output of the following Python code snippet?
X="hi"
print("%05d"%X)

(a) 00000hi
(b) 000hi
(c) hi000
(d) error
Answer: (d)
Explanation: The code snippet shown above results in an error because the above formatting option works only if ‘X’ is a number. Since in the above case ‘X’ is a string, an error is thrown.

Question. What will be the output of the following Python code snippet?
X="san-foundry"
print("%56s"%X)

(a) 56 blank spaces before san-foundry
(b) 56 blank spaces before san and foundry
(c) 56 blank spaces after san-foundry
(d) no change
Answer: (a)
Explanation: The formatting option print(“%Ns”,X) helps us add ‘N’ number of spaces before a given string ‘X’. Hence the output for the code snippet shown above will be 56 blank spaces before the string “san-foundry”.

Question. What will be the output of the following Python expression if x=456?
print("%-06d"%x)

(a) 000456
(b) 456000
(c) 456
(d) error
Answer: (c)
Explanation: The expression shown above results in the output 456.

Question. What will be the output of the following Python expression if X=345?
print("%06d"%X)

(a) 345000
(b) 000345
(c) 000000345
(d) 345000000
Answer: (b)
Explanation: The above expression returns the output 000345. It adds the required number of zeroes before the given number in order to make the number of digits 6 (as specified in this case).

Question. Which of the following formatting options can be used in order to add ‘n’ blank spaces after a given string ‘S’?
(a) print("-ns"%S)
(b) print("-ns"%S)
(c) print("%ns"%S)
(d) print("%-ns"%S)
Answer: (d)
Explanation: In order to add ‘n’ blank spaces after a given string ‘S’, we use the formatting option:(“%-ns”%S).

Question. What will be the output of the following Python expression if X = -122?
print("-%06d"%x)

(a) -000122
(b) 000122
(c) –00122
(d) -00122
Answer: (c)
Explanation: The given number is -122. Here the total number of digits (including the negative sign) should be 6 according to the expression. In addition to this, there is a negative sign in the given expression. Hence the output will be – -00122.

Question. What will be the output of the following Python expression if the value of x is 34?
print("%f"%x)

(a) 34.00
(b) 34.0000
(c) 34.000000
(d) 34.00000000
Answer: (c)
Explanation: The expression shown above normally returns the value with 6 decimal points if it is not specified with any number. Hence the output of this expression will be: 34.000000 (6 decimal points).

Question. What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)

(a) 56.00
(b) 56.24
(c) 56.23
(d) 0056.236
Answer: (b)
Explanation: The expression shown above rounds off the given number to the number of decimal places specified. Since the expression given specifies rounding off to two decimal places, the output of this expression will be 56.24. Had the value been x=56.234 (last digit being any number less than 5), the output would have been 56.23.

Question. What will be the output of the following Python expression if x=22.19?
print("%5.2f"%x)

(a) 22.1900
(b) 22.00000
(c) 22.19
(d) 22.20
Answer: (c)
Explanation: The output of the expression above will be 22.19. This expression specifies that the total number of digits (including the decimal point) should be 5, rounded off to two decimal places.

Question. The expression shown below results in an error.
print("-%5d0", 989)

(a) True
(b) False
Answer: (b)
Explanation: The expression shown above does not result in an error. The output of this expression is -%5d0 989. Hence this statement is incorrect.

Question. What will be the output of the following Python code snippet?
'%d %s %g you' %(1, 'hello', 4.0)

(a) Error
(b) 1 hello you 4.0
(c) 1 hello 4 you
(d) 1 4 hello you
Answer: (c)
Explanation: In the snippet of code shown above, three values are inserted into the target string. When we insert more than one value, we should group the values on the right in a tuple. The % formatting expression operator expects either a single item or a tuple of one or more items on its right side.

Question. The output of which of the codes shown below will be: “There are 4 blue birds.”?
(a) ‘There are %g %d birds.’ %4 %blue
(b) ‘There are %d %s birds.’ %(4, blue)
(c) ‘There are %s %d birds.’ %[4, blue]
(d) ‘There are %d %s birds.’ 4, blue
Answer: (b)
Explanation: The code ‘There are %d %s birds.’ %(4, blue) results in the output: There are 4 blue birds. When we insert more than one value, we should group the values on the right in a tuple.

Question. What will be the output of the python code shown below for various styles of format specifiers?
x=1234
res='integers:...%d...%-6d...%06d' %(x, x, x)
res

(a) ‘integers:…1234…1234 …001234’
(b) ‘integers…1234…1234…123400’
(c) ‘integers:… 1234…1234…001234’
(d) ‘integers:…1234…1234…001234’
Answer: (a)
Explanation: The code shown above prints 1234 for the format specified %d, ‘1234 ’ for the format specifier %-6d (minus ‘-‘ sign signifies left justification), and 001234 for the format specifier %06d. Hence the output of this code is: ‘integers:…1234…1234 …001234’

Question. What will be the output of the following Python code snippet?
x=3.3456789
'%f | %e | %g' %(x, x, x)

(a) Error
(b) ‘3.3456789 | 3.3456789+00 | 3.345678’
(c) ‘3.345678 | 3.345678e+0 | 3.345678’
(d) ‘3.345679 | 3.345679e+00 | 3.34568’
Answer: (d)
Explanation: The %f %e and %g format specifiers represent floating point numbers in different ways. %e and %E are the same, except that the exponent is in lowercase. %g chooses the format by number content. Hence the output of this code is: ‘3.345679 | 3.345679e+00 | 3.34568’.

Question. What will be the output of the following Python code snippet?
x=3.3456789
'%-6.2f | %05.2f | %+06.1f' %(x, x, x)

(a) ‘3.35 | 03.35 | +003.3’
(b) ‘3.3456789 | 03.3456789 | +03.3456789’
(c) Error
(d) ‘3.34 | 03.34 | 03.34+’
Answer: (a)
Explanation: The code shown above rounds the floating point value to two decimal places. In this code, a variety of addition formatting features such as zero padding, total field width etc. Hence the output of this code is: ‘3.35 | 03.35 | +003.3’.

Question. What will be the output of the following Python code snippet?
x=3.3456789
'%s' %x, str(x)

(a) Error
(b) (‘3.3456789’, ‘3.3456789’)
(c) (3.3456789, 3.3456789)
(d) (‘3.3456789’, 3.3456789)
Answer: (b)
Explanation: We can simply convert strings with a %s format expression or the str built-in function. Both of these methods have been shown in this code. Hence the output is: ) (‘3.3456789’, ‘3.3456789’)

Question. What will be the output of the following Python code snippet?
'%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'}

(a) Error
(b) No output
(c) ‘1 more foods’
(d) ‘1 more spam’
Answer: (d)
Explanation: String formatting also allows conversion targets on the left to refer to the keys in a dictionary coded on the right and fetch the corresponding values. In the code shown above, (qty) and (food) in the format string on the left refers to keys in thedictionary literal on the right and fetch their assorted values. Hence the output of the code shown above is: 1 more spam.

Question. What will be the output of the following Python code snippet?
a='hello'
q=10
vars()
(a) {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}
(b) {……Built in names set by Python……}
(c) {‘a’ : ‘hello’, ‘q’ : 10}
(d) Error

Answer: (a)
Explanation: The built in function vars() returns a dictionary containing all the variables that exist in the place. Hence the output of the code shown above is: {‘a’ : ‘hello’, ‘q’ : 10, ……..plus built-in names set by Python….}

Question. What will be the output of the following Python code?
s='{0}, {1}, and {2}'
s.format('hello', 'good', 'morning')
(a) ‘hello good and morning’
(b) ‘hello, good, morning’
(c) ‘hello, good, and morning’
(d) Error

Answer: (c)
Explanation: Within the subject string, curly braces designate substitution targets and arguments to be inserted either by position or keyword. Hence the output of the code shown above:’hello, good,and morning’.

Question. What will be the output of the following Python code?
s='%s, %s & %s'
s%('mumbai', 'kolkata', 'delhi')
(a) mumbai kolkata & delhi
(b) Error
(c) No output
(d) ‘mumbai, kolkata & delhi’

Answer: (d)
Explanation: In the code shown above, the format specifier %s is replaced by the designated substitution. Hence the output of the code shown above is: ‘mumbai, kolkata & delhi’.

Question. What will be the output of the following Python code?
t = '%(a)s, %(b)s, %(c)s'
t % dict(a='hello', b='world', c='universe')
(a) ‘hello, world, universe’
(b) ‘hellos, worlds, universes’
(c) Error
(d) hellos, world, universe

Answer: (a)
Explanation: Within the subject string, curly braces represent substitution targets and arguments to be inserted. Hence the output of the code shown above: ‘hello, world, universe’.

Question. What will be the output of the following Python code?
'{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])
(a) Error
(b) ‘2.5, 10, [1, 2]’
(c) 2.5, 10, 1, 2
(d) ’10, 2.5, [1, 2]’

Answer: (b)
Explanation: Since we have specified that the order of the output be: {a}, {0}, {abc}, hence the value of associated with {a} is printed first followed by that of {0} and {abc}. Hence the output of the code shown above is: ‘2.5, 10, [1, 2]’.

Question. What will be the output of the following Python code?
'{0:.2f}'.format(1.234)
(a) ‘1’
(b) ‘1.234’
(c) ‘1.23’
(d) ‘1.2’

Answer: (c)
Explanation: The code shown above displays the string method to round off a given decimal number to two decimal places. Hence the output of the code is: ‘1.23’.

Question. What will be the output of the following Python code?
'%x %d' %(255, 255)
(a) ‘ff, 255’
(b) ‘255, 255’
(c) ‘15f, 15f’
(d) Error

Answer: (a)
Explanation: The code shown above converts the given arguments to hexadecimal and decimal values and prints the result. This is done using the format specifiers %x and %d respectively. Hence the output of the code shown above is: ‘ff, 255’.

Question. The output of the two codes shown below is the same.
i. '{0:.2f}'.format(1/3.0)
ii. '%.2f'%(1/3.0)
(a) True
(b) False

Answer: (a)
Explanation: The two codes shown above represent the same operation but in different formats. The output of both of these functions is: ‘0.33’. Hence the statement is true.

Python Questions and Answers – Advanced Formatting Tools

Question. What will be the output of the following Python code?
l=list('HELLO')
'first={0[0]}, third={0[2]}'.format(l)
(a) ‘first=H, third=L’
(b) ‘first=0, third=2’
(c) Error
(d) ‘first=0, third=L’

Answer: (a)
Explanation: In the code shown above, the value for first is substituted by l[0], that is H and the value for third is substituted by l[2], that is L. Hence the output of the code shown above is: ‘first=H, third=L’. The list l= [‘H’, ‘E’, ‘L’, ‘L’, ‘O’].

Question. What will be the output of the following Python code?
l=list('HELLO')
p=l[0], l[-1], l[1:3]
'a={0}, b={1}, c={2}'.format(*p)
(a) Error
(b) “a=’H’, b=’O’, c=(E, L)”
(c) “a=H, b=O, c=[‘E’, ‘L’]”
(d) Junk value

Answer: (c)
Explanation: In the code shown above, the value for a is substituted by l[0], that is ‘H’, the value of b is substituted by l[-1], that is ‘O’ and the value for c is substituted by l[1:3]. Here the use of *p is to unpack a tuple items into individual function arguments.

Question. The formatting method \( \{1:<10\} \) represents the ___________ positional argument, _________ justified in a 10 character wide field.
(a) first, right
(b) second, left
(c) first, left
(d) second, right

Answer: (b)
Explanation: The formatting method \( \{1:<10\} \) represents the second positional argument, left justified in a 10 character wide field.

Question. What will be the output of the following Python code?
hex(255), int('FF', 16), 0xFF
(a) [0xFF, 255, 16, 255]
(b) (‘0xff’, 155, 16, 255)
(c) Error
(d) (‘0xff’, 255, 255)

Answer: (d)
Explanation: The code shown above converts the value 255 into hexadecimal, that is, 0xff. The value ‘FF’ into integer. Hence the output of the code shown is: (‘0xff’, 255, 255).

Question. The output of the two codes shown below is the same.
i. bin((2**16)-1)
ii. '{}'.format(bin((2**16)-1))
(a) True
(b) False

Answer: (a)
Explanation: The output of both of the codes shown above is ‘0b1111111111111111’. Hence the statement is true.

Question. What will be the output of the following Python code?
'{a}{b}{a}'.format(a='hello', b='world')
(a) ‘hello world’
(b) ‘hello’ ‘world’ ‘hello’
(c) ‘helloworldhello’
(d) ‘hello’ ‘hello’ ‘world’

Answer: (c)
Explanation: The code shown above prints the values substituted for a, b, a, in the same order. This operation is performed using the format function. Hence the output of the code is: ‘helloworldhello’.

Question. What will be the output of the following Python code?
D=dict(p='san', q='foundry')
'{p}{q}'.format(**D)
(a) Error
(b) sanfoundry
(c) san foundry
(d) {‘san’, ‘foundry’}

Answer: (b)
Explanation: The code shown above prints the values substituted for p and q in the same order. Note that there is no blank space between p and q. Hence the output is: sanfoundry.

Question. What will be the output of the following Python code?
'The {} side {1} {2}'.format('bright', 'of', 'life')
(a) Error
(b) ‘The bright side of life’
(c) ‘The {bright} side {of} {life}’
(d) No output

Answer: (a)
Explanation: The code shown above results in an error. This is because we have switched from automatic field numbering to manual field numbering, that is, from {} to {1}. Hence this code results in an error.

Question. What will be the output of the following Python code?
'{0:f}, {1:2f}, {2:05.2f}'.format(1.23456, 1.23456, 1.23456)
(a) Error
(b) ‘1.234560, 1.22345, 1.23’
(c) No output
(d) ‘1.234560, 1.234560, 01.23’

Answer: (d)
Explanation: In the code shown above, various formatting options are displayed using the format option. Hence the output of this code is: ‘1.234560, 1.234560, 01.23’

Question. What will be the output of the following Python code?
'%.2f%s' % (1.2345, 99)
(a) ‘1.2345’, ‘99’
(b) ‘1.2399’
(c) ‘1.234599’
(d) 1.23, 99

Answer: (b)
Explanation: In this code, we must notice that since multiple values haven been given, they should be enclosed in a tuple. Since the formatting format is %.2f, the value 1.2345 is reduced to two decimal places. Hence the output of the code shown above: ‘1.2399’.

Question. What will be the output of the following Python code?
'%s' %((1.23,),)
(a) ‘(1.23,)’
(b) 1.23,
(c) (,1.23)
(d) ‘1.23’

Answer: (a)
Explanation: The formatting expression accepts either a single substitution value, or a tuple of one or more items. Since single item can be given either by itself or within the tuple, a tuple to be formatted must be provided as a tested tuple. Hence the output of the code is: >>> ‘%s’ %((1.23,),).

Question. What will be the output of the following two codes?
i. '{0}'.format(4.56)
ii. '{0}'.format([4.56,])
(a) ‘4.56’, ‘4.56,’
(b) ‘4.56’, ‘[4.56]’
(c) 4.56, [4.56,]
(d) 4.56, [4.56,]

Answer: (b)
Explanation: The code shown above shows the formatting option on the same value, that is 4.56, where in the second case, the value is enclosed in a list. Hence the output of the code shown above is: ‘4.56’, ‘[4.56]’

Formatting Objective Questions & Solutions for

Download Multiple Choice Questions: Formatting ( )

Explore reliable practice questions for Formatting tailored for learners. Use these multiple-choice formats to evaluate preparedness and strengthen problem-solving skills.

Concept Clarification for Formatting

Cross-reference your completed choices with comprehensive NCERT solutions for to ensure absolute clarity across all sub-topics in this chapter.

Additional Study Resources for

Follow up your worksheet practice by attempting the interactive online MCQ test for this chapter to evaluate your execution speed. All platform resources are free to access.

FAQs

Where can I access latest Python Formatting MCQs with Answers?

You can get most exhaustive Python Formatting MCQs with Answers for free on StudiesToday.com. These MCQs for are updated for the 2026-27 academic session as per examination standards.

Are Assertion-Reasoning and Case-Study MCQs included in the [current-page:node:field_subject] [current-page:node:field_class] material?

Yes, our Python Formatting MCQs with Answers include the latest type of questions, such as Assertion-Reasoning and Case-based MCQs. 50% of the paper is now competency-based.

How do practicing [current-page:node:field_subject] MCQs help in scoring full marks in [current-page:node:field_class] exams?

By solving our Python Formatting MCQs with Answers, students can improve their accuracy and speed which is important as objective questions provide a chance to secure 100% marks in the .

Do you provide answers and explanations for Python Formatting MCQs with Answers?

Yes, MCQs for have answer key and brief explanations to help students understand logic behind the correct option as its important for 2026 competency-focused exams.

Can I practice these [current-page:node:field_subject] [current-page:node:field_class] MCQs online?

Yes, you can also access online interactive tests for Python Formatting MCQs with Answers on StudiesToday.com as they provide instant answers and score to help you track your progress in .