Test Index

Python Revision Tour Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 68 of 102
Marks: +1, -0
Select the correct output of the code :
S = "text#next"
print(S.strip("t"))
[CBSE 2024 Compartment]
Solution:  
Concept:
str.strip(chars) removes the given characters from both ends of the string (leading and trailing) until a different character is met. Characters in the middle are not touched.
Explanation:
S = "text#next"
Left end: the first 't' is removed; the next character 'e' stops the stripping.
Right end: the last 't' is removed; the next character 'x' stops the stripping.
The 't' characters inside (in "text" and "next") stay.
Output:
ext#nex
Answer:
Option A (ext#nex)
© examsnet.com
Advertisements
Go to Question: