educative.io

Educative

Rotate linked list solution question - negative number modulo in Python

In the solution of “Rotate a Linked List” from python learning path. There’s a function I don’t quite understand:

def adjust_rotations_needed(n, length):

  # If n is positive then number of rotations performed is from right side
  # and if n is negative then number of rotations performed from left side
  # Let's optimize the number of rotations.
  # Handle case if 'n' is a negative number.

  n = n % length

  if n < 0:

    n = n + length

If I have n as -9, and length is 7, before hitting “if n<0”, n will be (-9) %7 = 5.
My question is, in what circumstance that the program will hit “if n< 0:” line?

Thanks.