-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,715
  • 6
  • 21

3 Answers3

1

Use not

if not var1.endswith("/"):
    print("whatever")
Dharmesh
  • 1,874
  • 1
  • 9
  • 17
0
if not var1.endswith("/"):
    print("whatever")
MrE
  • 14,927
  • 10
  • 64
  • 89
0

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

if var1[-1] != '/':
   print("whatever")
Joe Iddon
  • 18,600
  • 5
  • 29
  • 49