Skip to main content

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
Question 1 of 40
★ FPSC ★ PPSC

Which function is used to format strings in Python?

Question 2 of 40
★ FPSC ★ PPSC

In Python, what does the % operator do when used for string formatting?

Question 3 of 40
★ FPSC ★ PPSC

Which of the following is an f-string in Python?

Question 4 of 40
★ FPSC ★ PPSC

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

Question 5 of 40
★ FPSC ★ PPSC

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

Question 6 of 40
★ FPSC ★ PPSC

In Python, what does the expression {:.2e} do in a formatted string?

Question 7 of 40
★ FPSC ★ PPSC

What is the purpose of the @wraps decorator in Python's functools module?

Question 8 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? s='{0}, {1}, and {2}' s.format('hello', 'good', 'morning')

Question 9 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? '%x %d' %(255, 255)

Question 10 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? class A: @staticmethod def a(x): print(x) A.a(100)

Question 11 of 40
★ FPSC ★ PPSC

What is the primary use of the @staticmethod decorator?

Question 12 of 40
★ 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)

Question 13 of 40
★ FPSC ★ PPSC

In Python, what is the purpose of the @classmethod decorator?

Question 14 of 40
★ 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

Question 15 of 40
★ FPSC ★ PPSC

What will be the output of the following two codes? i. '{0}'.format(4.56) ii. '{0}'.format([4.56,])

Question 16 of 40
★ FPSC ★ PPSC

In Python, what is the purpose of the locals() function?

Question 17 of 40
★ FPSC ★ PPSC

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

Question 18 of 40
★ 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)

Question 19 of 40
★ 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()

Question 20 of 40
★ FPSC ★ PPSC

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

Question 21 of 40
★ 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))

Question 22 of 40
★ FPSC ★ PPSC

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

Question 23 of 40
★ 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.

Question 24 of 40
★ FPSC ★ PPSC

Which module must be imported to use the @abstractmethod decorator in Python?

Question 25 of 40
★ FPSC ★ PPSC

What is the output of the code: print("{:<10}".format("hello"))?

Question 26 of 40
★ 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)

Question 27 of 40
★ 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)

Question 28 of 40
★ FPSC ★ PPSC

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

Question 29 of 40
★ FPSC ★ PPSC

The formatting method {1:<10} represents the . . . . . . . . positional argument, . . . . . . . . justified in a 10 character wide field.

Question 30 of 40
★ 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)

Question 31 of 40
★ FPSC ★ PPSC

Identify the decorator in the snippet of code shown below. def sf(): pass sf = mk(sf) @f def sf(): return

Question 32 of 40
★ FPSC ★ PPSC

Which built-in function is used to check if an object is an instance of a particular class?

Question 33 of 40
★ FPSC ★ PPSC

What is the purpose of the @staticmethod decorator compared to the @classmethod decorator?

Question 34 of 40
★ FPSC ★ PPSC

What will be the output of the following Python code? l=list('HELLO') 'first={0[0]}, third={0[2]}'.format(l)

Question 35 of 40
★ 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)

Question 36 of 40
★ 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)

Question 37 of 40
★ 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

Question 38 of 40
★ 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')

Question 39 of 40
★ FPSC ★ PPSC

In Python, which of the following is used to format a string left-justified within a field?

Question 40 of 40
★ FPSC ★ PPSC

What does the ** symbol do when used in a function's parameter list?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 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.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →