Computer Science
What will be the output of the following?
print("ComputerScience".split("er", 2))
- ["Computer", "Science"]
- ["Comput", "Science"]
- ["Comput", "erScience"]
- ["Comput", "er", "Science"]
Python String Manipulation
2 Likes
Answer
["Comput", "Science"]
Reason — The split() method splits a string into a list of substrings based on the specified delimiter. In this case, "er" is the delimiter. The second argument 2 is the maximum number of splits to be made. "ComputerScience" is split using "er" as the delimiter. The first occurrence of "er" splits "ComputerScience" into "Comput" and "Science". Since the 2 splits limit is applied, it does not continue searching for additional delimiters beyond the first one. Thus, the output is ['Comput', 'Science'].
Answered By
2 Likes
Related Questions
…………… function will always return tuple of 3 elements.
- index()
- split()
- partition()
- strip()
What will be the output of the following code?
A = 'Virtual Reality' A.replace('Virtual', 'Augmented')- Virtual Augmented
- Reality Augmented
- Augmented Virtual
- Augmented Reality
What is the ASCII equivalent decimal no. for 'Y'?
- 87
- 88
- 89
- 90
STR = "RGBCOLOR" colors = list(STR)How do we delete 'B' in given List colors?
- del colors[2]
- colors.remove("B")
- colors.pop(2)
- All of these