-1

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,

dmuensterer
  • 1,875
  • 11
  • 26

3 Answers3

1

Use not

if not var1.endswith("/"):
    print("whatever")
Dharmesh Fumakiya
  • 2,276
  • 2
  • 11
  • 17
0
if not var1.endswith("/"):
    print("whatever")
MrE
  • 19,584
  • 12
  • 87
  • 105
0

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

if var1[-1] != '/':
   print("whatever")
Joe Iddon
  • 20,101
  • 7
  • 33
  • 54