Computer Science
What is the output of the expression ?
country = 'International'
print(country.split("n"))
('I', 'ter', 'atio', 'aI')
['I', 'ter', 'atio', 'al']
['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
Error
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.
Related Questions
Identify the output of the following code snippet:
text = "PYTHONPROGRAM" text = text.replace('PY', '#') print(text)
- #THONPROGRAM
- ##THON#ROGRAM
- #THON#ROGRAM
- #YTHON#ROGRAM
Which of the following expressions evaluates to False ?
- not(True) and False
- True or False
- not(False and True)
- True and not(False)
What will be the output of the following code snippet ?
message = "World Peace" print(message[-2::-2])
What will be the output of the following code ?
tuple1 = (1, 2, 3) tuple2 = tuple1 tuple1 += (4, ) print(tuple1 == tuple2)
- True
- False
- tuple1
- Error