Reputation: 209
I have the following string for example:
' 24499 ? 00:02:05 sys-yg-ys'
How can I verify if the string ends with a string which I got from a result of a function (e.g sys-yg-ys
)?
I tried the following (just to check easy case) on the string above: result='' if (line.endswith('ys',len(line)-2,len(line)-1)): result='true'
but I didn't get true when I chech the value of result.
Upvotes: 4
Views: 8692
Reputation: 375
try this:
line = ' 24499 ? 00:02:05 sys-yg-ys'
result = False
print("Before test: " + str(result))
result = line.endswith('ys')
print("After test: " + str(result))
output:
Before test: False
After test: True
why you want to add 'start' and 'end' parameter?
Upvotes: 2
Reputation: 741
The str.endswith() function will do this.
For example: yourstring.endswith("sys-yg-ys")
Upvotes: 18