Skip to content
Exercises · Q2

Q.Consider the following string myAddress: myAddress = "WZ-1,New Ganga Nagar,New Delhi" What will be the output of following string operations : i. print(myAddress.lower())
ii. print(myAddress.upper())
iii. print(myAddress.count('New'))
iv. print(myAddress.find('New'))
v. print(myAddress.rfind('New'))
vi. print(myAddress.split(','))
vii. print(myAddress.split(' '))
viii. print(myAddress.replace('New','Old'))
ix. print(myAddress.partition(','))
x. print(myAddress.index('Agra'))

Odisha ChseTextbookSubjective· 4mImportance★★★★★est
62% · 8/13 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Ten string-method calls on myAddress = "WZ-1,New Ganga Nagar,New Delhi" — the highlights: "New" occurs twice (indices 5 and 21), split() results differ by separator, and index('Agra') raises a ValueError because unlike find(), index() does not return -1.

First map the positions that matter. Counting characters of "WZ-1,New Ganga Nagar,New Delhi":

W(0) Z(1) -(2) 1(3) ,(4) N(5) e(6) w(7) ' '(8) G(9)...r(19) ,(20) N(21) e(22) w(23) ' '(24) D(25)...i(29)

So the substring "New" starts at index 5 (first) and index 21 (second). Now each statement:

#StatementHow it evaluatesOutput
imyAddress.lower()all letters to lowercasewz-1,new ganga nagar,new delhi
iimyAddress.upper()all letters to uppercaseWZ-1,NEW GANGA NAGAR,NEW DELHI
iiimyAddress.count('New')non-overlapping occurrences of "New"2
ivmyAddress.find('New')index of the FIRST occurrence5
vmyAddress.rfind('New')index of the LAST occurrence (search from right)21
vimyAddress.split(',')cut at every comma → list of 3 parts['WZ-1', 'New Ganga Nagar', 'New Delhi']
viimyAddress.split(' ')cut at every space — commas stay glued to words['WZ-1,New', 'Ganga', 'Nagar,New', 'Delhi']
viiimyAddress.replace('New','Old')replaces BOTH occurrencesWZ-1,Old Ganga Nagar,Old Delhi
ixmyAddress.partition(',')splits at the FIRST comma only, into a 3-tuple (before, separator, after)('WZ-1', ',', 'New Ganga Nagar,New Delhi')
xmyAddress.index('Agra')"Agra" does not occur; index() raises an exception instead of returning -1ValueError: substring not found

Complete run:

wz-1,new ganga nagar,new delhi
WZ-1,NEW GANGA NAGAR,NEW DELHI
2
5
21
['WZ-1', 'New Ganga Nagar', 'New Delhi'] …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.