OneCompiler

How to check if a string ends with a particular character in python?

I'm reading input from the user and I want to tell whether the input entered is a question or not.

To do this, I'm looking at the last character at the string, if its a ? then its a question else not.

How can I do it?

1 Answer

5 years ago by

You can do it with the help of endswith()

s = "onecompiler"

if(s.endswith('?')):
   print("yes")
else:
   print("no")
5 years ago by Divya