I have a string:
b = 'week'
I want to check if the last character is an "s". If not, append an "s".
Is there a Pythonic one-liner for this one?
You could use a conditional expression:
b = b + 's' if not b.endswith('s') else b
Personally, I'd still stick with two lines, however:
if not b.endswith('s'):
b += 's'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With