Select the correct output of the code : S = “text#next” print(S.strip(“t”))

Select the correct output of the code:

Code:

S = "text#next"
print(S.strip("t"))

Options:

  • (A) ext#nex
  • (B) ex#nex
  • (C) text#nex
  • (D) ext#next

Answer: (A) ext#nex

Explanation:

The strip() method in Python is used to remove leading and trailing characters (specified in the argument) from a string. It does not affect characters in the middle of the string.

In this case, the string "text#next" has the characters "t" specified for removal:

S = "text#next"
strip("t") will remove the 't' characters from both the beginning and the end of the string.

Step-by-Step Execution:

1. The strip("t") function will remove "t" from the left (beginning) and right (end) of the string.

Original string: "text#next"
After strip("t"): "ext#nex"

Final Output:

The final output of the code is ext#nex.

Related posts

The Decline of BSNL in Mankapur: A Case of Lost Rural Connectivity

The Most Popular YouTube Alternatives for Video Streaming in 2025

India’s Data Centre Capacity to Double by Fiscal 2027: Crisil Report