KnowledgeBoat Logo

Computer Science

What is the output of the expression ?

country = 'International'
print(country.split("n"))
  1. ('I', 'ter', 'atio', 'aI')
  2. ['I', 'ter', 'atio', 'al']
  3. ['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
  4. Error

Python String Manipulation

1 Like

Answer

['I', 'ter', 'atio', 'al']

Reason — The code defines a string country = 'International' and uses the split("n") method to split the string at each occurrence of the letter "n". This breaks the string into a list of parts: ['I', 'ter', 'atio', 'al'], with each occurrence of "n" removed and the remaining substrings stored as separate elements in the list. The print() function then outputs this list.

Answered By

1 Like


Related Questions