What is the output and how plz tell me?

x = “xyztv”
i = “t”
while i in x:
x = x[:-1]
print(i)

The output is:

t
t

You can verify this by simply executing the code.
In every iteration, the last character of x is removed. i in x is true when the char t exists in the string x. After 2 iterations, ‘t’ is removed from x and the loop stops.

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

1 Like