I have a question about the Python string output

Asked 2 years ago, Updated 2 years ago, 100 views

I wrote the code through the process from 2.1 to 2.3

word = "Love it or leave it."

start = word[11:]

end = word[11:16]

May I know how to use the print of the last 2.4 question that should be in the last line?

string python print

2022-09-20 10:58

1 Answers

This seems to be a problem created with the intention of trying the index method.

>>> word = "Love it or leave it."
>>> word.index("leave")
11
>>> start = word.index("leave")
>>> end = word.index(" ", start)
>>> end
16
>>> word[start:end]
'leave'
>>> print(word[start:end])
leave


2022-09-20 10:58

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.