Formatting And Decorators — Part 2 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Formatting And Decorators — Part 2 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.
Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40
Verified Practice Questions
Interactive test mode with detailed academic worked solutions
Live Progress|0/40 answered
✓0 correct
✗0 wrong
0% score
🎉 Set complete! All 40 questions answered.
Question 1 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? D=dict(p='Exam', q='Veda') '{p}{q}'.format(**D)
Correct Answer: Option B — ExamVeda
Detailed Academic Explanation:
ExamVeda is the correct answer to “What will be the output of the following Python code? D=dict(p='Exam', q='Veda') '{p}{q}'.format(**D)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 2 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? '{a}{b}{a}'.format(a='hello', b='world')
Correct Answer: Option C — 'helloworldhello'
Detailed Academic Explanation:
'helloworldhello' is the correct answer to “What will be the output of the following Python code? '{a}{b}{a}'.format(a='hello', b='world')”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 3 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, what is the role of the @functools.lru_cache decorator?
Correct Answer: Option A — Cache function results
Detailed Academic Explanation:
Cache function results is the correct answer to “In Python, what is the role of the @functools.lru_cache decorator”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 4 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of a decorator in Python?
Correct Answer: Option A — Modify the behavior of functions
Detailed Academic Explanation:
Modify the behavior of functions is the correct answer to “What is the purpose of a decorator in Python”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 5 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x=3.3456789 '%f | %e | %g' %(x, x, x)
Correct Answer: Option D — '3.345679 | 3.345679e+00 | 3.34568'
Detailed Academic Explanation:
'3.345679 | 3.345679e+00 | 3.34568' is the correct answer to “What will be the output of the following Python code snippet? x=3.3456789 '%f | %e | %g' %(x, x, x)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 6 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following formatting options can be used in order to add 'n' blank spaces after a given string 'S'?
Correct Answer: Option C — print("%-ns"%S)
Detailed Academic Explanation:
print("%-ns"%S) is the correct answer to “Which of the following formatting options can be used in order to add 'n' blank spaces after a given string 'S'”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 7 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? s='%s, %s & %s' s%('mumbai', 'kolkata', 'delhi')
Correct Answer: Option D — 'mumbai, kolkata & delhi'
Detailed Academic Explanation:
'mumbai, kolkata & delhi' is the correct answer to “What will be the output of the following Python code? s='%s, %s & %s' s%('mumbai', 'kolkata', 'delhi')”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 8 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, what is the primary use of the super() function in a subclass constructor?
Correct Answer: Option B — Initialize superclass
Detailed Academic Explanation:
Initialize superclass is the correct answer to “In Python, what is the primary use of the super() function in a subclass constructor”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 9 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, what is the purpose of the @property decorator?
Correct Answer: Option A — Define getter methods
Detailed Academic Explanation:
Define getter methods is the correct answer to “In Python, what is the purpose of the @property decorator”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 10 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def ordi(): print("Ordinary") ordi ordi()
Correct Answer: Option A — Address Ordinary
Detailed Academic Explanation:
Address Ordinary is the correct answer to “What will be the output of the following Python code? def ordi(): print("Ordinary") ordi ordi()”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 11 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? hex(255), int('FF', 16), 0xFF
Correct Answer: Option D — ('0xff', 255, 255)
Detailed Academic Explanation:
('0xff', 255, 255) is the correct answer to “What will be the output of the following Python code? hex(255), int('FF', 16), 0xFF”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 12 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the primary use of the @final decorator in Python?
Correct Answer: Option D — Mark a variable as final
Detailed Academic Explanation:
Mark a variable as final is the correct answer to “What is the primary use of the @final decorator in Python”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 13 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? '%.2f%s' % (1.2345, 99)
Correct Answer: Option B — '1.2399'
Detailed Academic Explanation:
'1.2399' is the correct answer to “What will be the output of the following Python code? '%.2f%s' % (1.2345, 99)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 14 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the role of the @abstractmethod decorator in Python?
Correct Answer: Option C — Mark a method as abstract
Detailed Academic Explanation:
Mark a method as abstract is the correct answer to “What is the role of the @abstractmethod decorator in Python”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 15 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? '%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'}
Correct Answer: Option D — '1 more spam'
Detailed Academic Explanation:
'1 more spam' is the correct answer to “What will be the output of the following Python code snippet? '%(qty)d more %(food)s' %{'qty':1, 'food': 'spam'}”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 16 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? X=”Exam-Veda” print(“%56s”,X)
Correct Answer: Option A — 56 blank spaces before Exam-Veda
Detailed Academic Explanation:
56 blank spaces before Exam-Veda is the correct answer to “What will be the output of the following Python code snippet? X=”Exam-Veda” print(“%56s”,X)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 17 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python function? def f(p, q): return p%q f(0, 2) f(2, 0)
Correct Answer: Option C — 0 Zero Division Error
Detailed Academic Explanation:
0 Zero Division Error is the correct answer to “What will be the output of the following Python function? def f(p, q): return p%q f(0, 2) f(2, 0)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 18 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the output of the code: print("{:.2f}".format(3.14159))?
Correct Answer: Option A — 3.14
Detailed Academic Explanation:
3.14 is the correct answer to “What is the output of the code: print("{:.2f}".format(3.14159))”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 19 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? X=”hi” print(“05d”%X)
Correct Answer: Option D — error
Detailed Academic Explanation:
error is the correct answer to “What will be the output of the following Python code snippet? X=”hi” print(“05d”%X)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
A function with parameters cannot be decorated.
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “A function with parameters cannot be decorated.”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 21 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In the following Python code, which function is the decorator? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()
Correct Answer: Option B — mk()
Detailed Academic Explanation:
mk() is the correct answer to “In the following Python code, which function is the decorator? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 22 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The output of which of the codes shown below will be: "There are 4 blue birds."?
Correct Answer: Option B — 'There are %d %s birds.' %(4, blue)
Detailed Academic Explanation:
'There are %d %s birds.' %(4, blue) is the correct answer to “The output of which of the codes shown below will be: "There are 4 blue birds."”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 23 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? '%d %s %g you' %(1, 'hello', 4.0)
Correct Answer: Option C — 1 hello 4 you
Detailed Academic Explanation:
1 hello 4 you is the correct answer to “What will be the output of the following Python code snippet? '%d %s %g you' %(1, 'hello', 4.0)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 24 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the purpose of the @classmethod decorator compared to the @staticmethod decorator?
Correct Answer: Option B — Operate on instance data
Detailed Academic Explanation:
Operate on instance data is the correct answer to “What is the purpose of the @classmethod decorator compared to the @staticmethod decorator”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 25 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
The output of the two codes shown below is the same. i. bin((2**16)-1) ii. '{}'.format(bin((2**16)-1))
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The output of the two codes shown below is the same. i. bin((2**16)-1) ii. '{}'.format(bin((2**16)-1))”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 26 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? '{0:.2f}'.format(1.234)
Correct Answer: Option C — '1.23'
Detailed Academic Explanation:
'1.23' is the correct answer to “What will be the output of the following Python code? '{0:.2f}'.format(1.234)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 27 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which symbol is used to denote a decorator in Python syntax?
Correct Answer: Option A — @
Detailed Academic Explanation:
@ is the correct answer to “Which symbol is used to denote a decorator in Python syntax”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 28 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which decorator is used to cache the results of a function call in Python?
Correct Answer: Option A — @cached
Detailed Academic Explanation:
@cached is the correct answer to “Which decorator is used to cache the results of a function call in Python”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 29 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? '%s' %((1.23,),)
Correct Answer: Option A — '(1.23,)'
Detailed Academic Explanation:
'(1.23,)' is the correct answer to “What will be the output of the following Python code? '%s' %((1.23,),)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 30 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What is the primary purpose of the functools.partial function in Python?
Correct Answer: Option C — Create a wrapper function
Detailed Academic Explanation:
Create a wrapper function is the correct answer to “What is the primary purpose of the functools.partial function in Python”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 31 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is used to format a string with left-aligned text within a field?
Correct Answer: Option D — =
Detailed Academic Explanation:
= is the correct answer to “Which of the following is used to format a string with left-aligned text within a field”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 32 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python expression if x=456? print("%-06d"%x)
Correct Answer: Option C — 456
Detailed Academic Explanation:
456 is the correct answer to “What will be the output of the following Python expression if x=456? print("%-06d"%x)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 33 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def f(x): def f1(*args, **kwargs): print("*", 5) x(*args, **kwargs) print("*", 5) return f1 @f def p(m): p(m) print("hello")
Correct Answer: Option D — hello
Detailed Academic Explanation:
hello is the correct answer to “What will be the output of the following Python code? def f(x): def f1(*args, **kwargs): print("*", 5) x(*args, **kwargs) print("*", 5) return f1 @f def p(m): p(m) print("hello")”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 34 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? def f(x): def f1(*args, **kwargs): print("*"* 5) x(*args, **kwargs) print("*"* 5) return f1 def a(x): def f1(*args, **kwargs): print("%"* 5) x(*args, **kwargs) print("%"* 5) return f1 @f @a def p(m): print(m) p("hello")
Correct Answer: Option A — ***** %%%%% hello %%%%% *****
Detailed Academic Explanation:
***** %%%%% hello %%%%% ***** is the correct answer to “What will be the output of the following Python code? def f(x): def f1(*args, **kwargs): print("*"* 5) x(*args, **kwargs) print("*"* 5) return f1 def a(x): def f1(*args, **kwargs): print("%"* 5) x(*args, **kwargs) print("%"* 5) return f1 @f @a def p(m): print(m) p("hello")”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 35 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code? 'The {} side {1} {2}'.format('bright', 'of', 'life')
Correct Answer: Option A — Error
Detailed Academic Explanation:
Error is the correct answer to “What will be the output of the following Python code? 'The {} side {1} {2}'.format('bright', 'of', 'life')”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 36 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? a='hello' q=10 vars()
Correct Answer: Option A — {'a' : 'hello', 'q' : 10, ........plus built-in names set by Python....}
Detailed Academic Explanation:
{'a' : 'hello', 'q' : 10, ........plus built-in names set by Python....} is the correct answer to “What will be the output of the following Python code snippet? a='hello' q=10 vars()”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 37 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
In Python, what does the expression {:#x} do in a formatted string?
Correct Answer: Option D — Formats a number in binary
Detailed Academic Explanation:
Formats a number in binary is the correct answer to “In Python, what does the expression {:#x} do in a formatted string”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 38 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which format specifier is used to represent an integer in binary form in a formatted string?
Correct Answer: Option B — %d
Detailed Academic Explanation:
%d is the correct answer to “Which format specifier is used to represent an integer in binary form in a formatted string”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 39 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python expression if X = -122? print("-%06d"%x)
Correct Answer: Option C — -122
Detailed Academic Explanation:
-122 is the correct answer to “What will be the output of the following Python expression if X = -122? print("-%06d"%x)”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
Question 40 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
Which of the following is a correct way to define a decorator function in Python?
Correct Answer: Option C — def decorator(): def func_wrapper():
Detailed Academic Explanation:
def decorator(): def func_wrapper(): is the correct answer to “Which of the following is a correct way to define a decorator function in Python”. This question is standard in competitive examination syllabi for Formatting And Decorators.
💡Key Conceptual Anchor:Formatting And Decorators
✓Link copied to clipboard
Continue Your Practice
Advance Html — Part 1
Master the next curriculum module with 40 exam-standard MCQs.
💡Examiner's Advisory for Programming & Software Development
In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.