DEV Community

Discussion on: Interview Qs Decoded - # 2

Collapse
 
hammertoe profile image
Matt Hamilton

Actually just realised an even more concise way in Python. The slice operator takes a step as an optional 3rd argument, and I just found out the step can be negative.

>>> str = "Reverse me!"
>>> str[::-1]
'!em esreveR'

So...

def revFunction(str):
  return str[::-1]