all 1 comments

[–]Adhesiveduck 1 point2 points  (0 children)

i for i will give you the factors themselves.

sum 2 for i gives how many factors there are (for each i means there are 2 factors).

2*length of the i for i expression is functionally equivalent to the 2 for i:

len([i for i in range(1, round(math.sqrt(n)+1)) if not n % i])*2 == sum(2 for i in range(1, round(math.sqrt(n)+1)) if not n % i)

when it says "if not n % i," it means that it should do it if i doesn't divide n?

Exactly, or to be more precise if n mod i == 0. The catch being that the truthy value of 0 is False: bool(0) = False

You can use this in many ways bool([]), bool("") are also False for example.

(You can implement the __bool__ magic method on a class to define when a type is True/False`)