Why this code doesn't give error?

def isPrime(N):
    for i in range(2, N):
        if (N % i) == 0: 
            return False
    else:
        return True

There’s a concept of for-else in python. Here else part is executed, when loop is not terminated by a break statement.
You can refer these for more information:-
4. More Control Flow Tools — Python 3.11.3 documentation (4.4)

2 Likes

Ohh…Thank you !