As I have read in this answer: What is tail recursion? tail recursion is a special case of recursion where the calling function does no more computation after making a recursive call.
Here after the recursive call we just assign the result to another variable. Can we consider this code as tail recursion?
class Solution:
def swapPairs(self, head: ListNode) -> ListNode:
if not head or not head.next:
return head
head_ = head
head_next = head.next
head_next_next = head.next.next
head_next.next = head_
head_.next = self.swapPairs(head_next_next)
return head_next