Formatting And Decorators — Part 1 MCQs with Explanations
Practice high-yield Programming & Software Development MCQs on Formatting And Decorators — Part 1 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
Which function is used to format strings in Python?
Correct Answer: Option A — format()
Detailed Academic Explanation:
format() is the correct answer to “Which function is used to format strings in Python”. 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
In Python, what does the % operator do when used for string formatting?
Correct Answer: Option D — Calculates exponentiation
Detailed Academic Explanation:
Calculates exponentiation is the correct answer to “In Python, what does the % operator do when used for string formatting”. 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
Which of the following is an f-string in Python?
Correct Answer: Option A — f"Hello {name}"
Detailed Academic Explanation:
f"Hello {name}" is the correct answer to “Which of the following is an f-string in Python”. 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 will be the output of the following Python expression if x=22.19? print("%5.2f"%x)
Correct Answer: Option C — 22.19
Detailed Academic Explanation:
22.19 is the correct answer to “What will be the output of the following Python expression if x=22.19? print("%5.2f"%x)”. 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
The expression shown below results in an error. print("-%5d0",989)
Correct Answer: Option B — False
Detailed Academic Explanation:
False is the correct answer to “The expression shown below results in an error. print("-%5d0",989)”. 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
In Python, what does the expression {:.2e} do in a formatted string?
Correct Answer: Option A — Formats a number in scientific notation
Detailed Academic Explanation:
Formats a number in scientific notation is the correct answer to “In Python, what does the expression {:.2e} do in a formatted string”. 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 is the purpose of the @wraps decorator in Python's functools module?
Correct Answer: Option A — Preserve original function's metadata
Detailed Academic Explanation:
Preserve original function's metadata is the correct answer to “What is the purpose of the @wraps decorator in Python's functools module”. 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
What will be the output of the following Python code? s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')
Correct Answer: Option C — 'hello, good, and morning'
Detailed Academic Explanation:
'hello, good, and morning' is the correct answer to “What will be the output of the following Python code? s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')”. 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
What will be the output of the following Python code? '%x %d' %(255, 255)
Correct Answer: Option A — 'ff, 255'
Detailed Academic Explanation:
'ff, 255' is the correct answer to “What will be the output of the following Python code? '%x %d' %(255, 255)”. 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? class A: @staticmethod def a(x): print(x) A.a(100)
Correct Answer: Option C — 100
Detailed Academic Explanation:
100 is the correct answer to “What will be the output of the following Python code? class A: @staticmethod def a(x): print(x) A.a(100)”. 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 is the primary use of the @staticmethod decorator?
Correct Answer: Option A — Define a static method
Detailed Academic Explanation:
Define a static method is the correct answer to “What is the primary use of the @staticmethod decorator”. 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 will be the output of the following Python code? def f(x): def f1(a, b): print("hello") if b==0: print("NO") return return f(a, b) return f1 @f def f(a, b): return a%b f(4,0)
Correct Answer: Option A — hello NO
Detailed Academic Explanation:
hello NO is the correct answer to “What will be the output of the following Python code? def f(x): def f1(a, b): print("hello") if b==0: print("NO") return return f(a, b) return f1 @f def f(a, b): return a%b f(4,0)”. 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
In Python, what is the purpose of the @classmethod decorator?
Correct Answer: Option A — Define class methods
Detailed Academic Explanation:
Define class methods is the correct answer to “In Python, what is the purpose of the @classmethod decorator”. 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
The following python code can work with . . . . . . . . parameters. def f(x): def f1(*args, **kwargs): print("Examveda") return x(*args, **kwargs) return f1
Correct Answer: Option C — any number of
Detailed Academic Explanation:
any number of is the correct answer to “The following python code can work with . . . . . . . . parameters. def f(x): def f1(*args, **kwargs): print("Examveda") return x(*args, **kwargs) return f1”. 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 two codes? i. '{0}'.format(4.56) ii. '{0}'.format([4.56,])
Correct Answer: Option B — '4.56', '[4.56]'
Detailed Academic Explanation:
'4.56', '[4.56]' is the correct answer to “What will be the output of the following two codes? i. '{0}'.format(4.56) ii. '{0}'.format([4.56,])”. 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
In Python, what is the purpose of the locals() function?
Correct Answer: Option C — Define instance methods
Detailed Academic Explanation:
Define instance methods is the correct answer to “In Python, what is the purpose of the locals() function”. 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 expression if X=345? print(“%06d”%X)
Correct Answer: Option B — 000345
Detailed Academic Explanation:
000345 is the correct answer to “What will be the output of the following Python expression if X=345? print(“%06d”%X)”. 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 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)
Correct Answer: Option C — "a=H, b=O, c=['E', 'L']"
Detailed Academic Explanation:
"a=H, b=O, c=['E', 'L']" is the correct answer to “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)”. 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? def mk(x): def mk1(): print("Decorated") x() return mk1 def mk2(): print("Ordinary") p = mk(mk2) p()
Correct Answer: Option D — Decorated Ordinary
Detailed Academic Explanation:
Decorated Ordinary is the correct answer to “What will be the output of the following Python code? 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 20 of 40
★ FPSC
★ PPSC
★ FPSC
★ PPSC
What will be the output of the following Python code snippet? x=3.3456789 '%s' %x, str(x)
Correct Answer: Option B — ('3.3456789', '3.3456789')
Detailed Academic Explanation:
('3.3456789', '3.3456789') is the correct answer to “What will be the output of the following Python code snippet? x=3.3456789 '%s' %x, str(x)”. 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
What will be the output of the following Python code? def d(f): def n(*args): return '$' + str(f(*args)) return n @d def p(a, t): return a + a*t print(p(100,0))
Correct Answer: Option B — $100
Detailed Academic Explanation:
$100 is the correct answer to “What will be the output of the following Python code? def d(f): def n(*args): return '$' + str(f(*args)) return n @d def p(a, t): return a + a*t print(p(100,0))”. 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
What will be the output of the following Python expression if the value of x is 34? print(“%f”%x)
Correct Answer: Option C — 34.000000
Detailed Academic Explanation:
34.000000 is the correct answer to “What will be the output of the following Python expression if the value of x is 34? print(“%f”%x)”. 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
The . . . . . . . . symbol along with the name of the decorator function can be placed above the definition of the function to be decorated works as an alternate way for decorating a function.
Correct Answer: Option C — @
Detailed Academic Explanation:
@ is the correct answer to “The . . . . . . . . symbol along with the name of the decorator function can be placed above the definition of the function to be decorated works as an alternate way for decorating a function.”. 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
Which module must be imported to use the @abstractmethod decorator in Python?
Correct Answer: Option A — abc
Detailed Academic Explanation:
abc is the correct answer to “Which module must be imported to use the @abstractmethod decorator in Python”. 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
What is the output of the code: print("{:<10}".format("hello"))?
Correct Answer: Option A — "hello"
Detailed Academic Explanation:
"hello" is the correct answer to “What is the output of the code: print("{:<10}".format("hello"))”. 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
The output of the two codes shown below is the same. i. '{0:.2f}'.format(1/3.0) ii. '%.2f'%(1/3.0)
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. '{0:.2f}'.format(1/3.0) ii. '%.2f'%(1/3.0)”. 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
What will be the output of the following Python code? '{0:f}, {1:2f}, {2:05.2f}'.format(1.23456, 1.23456, 1.23456)
Correct Answer: Option D — '1.234560, 1.234560, 01.23'
Detailed Academic Explanation:
'1.234560, 1.234560, 01.23' is the correct answer to “What will be the output of the following Python code? '{0:f}, {1:2f}, {2:05.2f}'.format(1.23456, 1.23456, 1.23456)”. 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
What will be the output of the following Python code? '{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])
Correct Answer: Option B — '2.5, 10, [1, 2]'
Detailed Academic Explanation:
'2.5, 10, [1, 2]' is the correct answer to “What will be the output of the following Python code? '{a}, {0}, {abc}'.format(10, a=2.5, abc=[1, 2])”. 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
The formatting method {1:<10} represents the . . . . . . . . positional argument, . . . . . . . . justified in a 10 character wide field.
Correct Answer: Option B — second, left
Detailed Academic Explanation:
second, left is the correct answer to “The formatting method {1:<10} represents the . . . . . . . . positional argument, . . . . . . . . justified in a 10 character wide field.”. 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 will be the output of the following Python code? def c(f): def inner(*args, **kargs): inner.co += 1 return f(*args, **kargs) inner.co = 0 return inner @c def fnc(): pass if __name__ == '__main__': fnc() fnc() fnc() print(fnc.co)
Correct Answer: Option B — 3
Detailed Academic Explanation:
3 is the correct answer to “What will be the output of the following Python code? def c(f): def inner(*args, **kargs): inner.co += 1 return f(*args, **kargs) inner.co = 0 return inner @c def fnc(): pass if __name__ == '__main__': fnc() fnc() fnc() print(fnc.co)”. 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
Identify the decorator in the snippet of code shown below. def sf(): pass sf = mk(sf) @f def sf(): return
Correct Answer: Option D — mk
Detailed Academic Explanation:
mk is the correct answer to “Identify the decorator in the snippet of code shown below. def sf(): pass sf = mk(sf) @f def sf(): return”. 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
Which built-in function is used to check if an object is an instance of a particular class?
Correct Answer: Option A — isinstance()
Detailed Academic Explanation:
isinstance() is the correct answer to “Which built-in function is used to check if an object is an instance of a particular class”. 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 is the purpose of the @staticmethod decorator compared to the @classmethod decorator?
Correct Answer: Option C — Decorate class methods
Detailed Academic Explanation:
Decorate class methods is the correct answer to “What is the purpose of the @staticmethod decorator compared to the @classmethod decorator”. 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? l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)
Correct Answer: Option A — 'first=H, third=L'
Detailed Academic Explanation:
'first=H, third=L' is the correct answer to “What will be the output of the following Python code? l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)”. 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 snippet? x=3.3456789 '%-6.2f | %05.2f | %+06.1f' %(x, x, x)
Correct Answer: Option A — '3.35 | 03.35 | +003.3'
Detailed Academic Explanation:
'3.35 | 03.35 | +003.3' is the correct answer to “What will be the output of the following Python code snippet? x=3.3456789 '%-6.2f | %05.2f | %+06.1f' %(x, x, x)”. 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
The two snippets of the following Python codes are equivalent. CODE 1 @f def f1(): print(“Hello”) CODE 2 def f1(): print(“Hello”) f1 = f(f1)
Correct Answer: Option A — True
Detailed Academic Explanation:
True is the correct answer to “The two snippets of the following Python codes are equivalent. CODE 1 @f def f1(): print(“Hello”) CODE 2 def f1(): print(“Hello”) f1 = f(f1)”. 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
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
Correct Answer: Option A — 'integers:…1234…1234 …001234'
Detailed Academic Explanation:
'integers:…1234…1234 …001234' is the correct answer to “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”. 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
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')
Correct Answer: Option A — 'hello, world, universe'
Detailed Academic Explanation:
'hello, world, universe' is the correct answer to “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')”. 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
In Python, which of the following is used to format a string left-justified within a field?
Correct Answer: Option A — <
Detailed Academic Explanation:
< is the correct answer to “In Python, which of the following is used to format a string left-justified within a field”. 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
What does the ** symbol do when used in a function's parameter list?
Correct Answer: Option D — Raises an exception
Detailed Academic Explanation:
Raises an exception is the correct answer to “What does the ** symbol do when used in a function's parameter list”. 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.