class Solution(object): def reverseStr(self, s, k): """ :type s: str :type k: int :rtype: str """ return s[:k][::-1] + s[k:2*k] + self.reverseStr(s[2*k:], k) if s else ""
help! what does it means when it follow the recursive part?
It means when current
s is empty string, just return an empty string. One thing to keep in mind is during the recursion, current
s is changing since we did some slicing in previous step.
Cool! So it means that the if-else statement acts on the argument s of the function.I just do not know this grammar because i just learned python last week.
BTW，if i put this if-else statement In the body of the function, it still work the same, right?