DEV Community

loading...

Discussion on: Interview Qs Decoded - # 2

Collapse
cat profile image
Cat Author

Yesss I was waiting for a Python response!!!

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]