[Tutor] Slicing index
Carlene Wong
cthwong at yahoo.com
Sun Oct 18 08:57:37 EDT 2020
Hello, I’m new but I’m getting trouble with slicing an index into another.
Eg. Def mysentence (sentence, old, new)
If old in sentence[-4:]:
n= sentence.index(old)
newsent=Sentence [:n]+new
return newsent
return mysentence
print(mysentence(“Hello there, it’s raining cats and cats”, “ cats”, “ dogs“)
It keeps printing
Hello there, it’s raining dogs
Your help
Sent from my iPhone
More information about the Tutor
mailing list