Search code examples
pythoninverse

Python inverse endswith() method


I hava a very simple piece of code, similar to this:

if var1.endswith("/"):
    print("whatever")

What can I do to inverse the if, except using an else statement? Like I want to print "whatever" if var1 does not end with "/"

Thanks,


Solution

  • In addition to the other answers, you could just index the last char of the string:

    if var1[-1] != '/':
       print("whatever")