isPrime functions in Python and Java This Python code looks messy to me. Am I doing any wrong style, or is this how Python looks like?

def is_prime(number):
    """check whether the @param number is a prime number"""
    is_prime = True
    for i in range(2, (number - 1)):
        is_prime = ((number % i) != 0)
        if not is_prime:
            return is_prime
    return is_prime


This Java code looks more clean, maybe due to a lot of empty lines generated due to the { } brackets:

private boolean isPrime(int toCheck)
{
    boolean isPrime = true;

    for (int i = 2; i &lt; toCheck; i++)
    {
        isPrime = ((toCheck % i) != 0);
        if (!isPrime)
        {
            return isPrime;
        }
    }

    return isPrime;
}


Python version 2.6.
This is a pretty literal translation of the algorithm. Let's first review the code itself and then check how we could reimagine it in python:


I'm not sure why there is a declaration for is_prime or isPrime respectively. It can be inlined, making the code look as follows:

for i in range(2, (number - 1)):
    if (number % i) == 0:
        return False
return True


This uses some minor formatting simplifications, like dropping extraneous parentheses.
The next step is then to actually optimize the program.
In this instance, using xrange over range is preferred, since you don't need to store the whole list of numbers before iterating over it, which is what range does. Note that this only applies for python 2.x, since xrange is not available for python 3.x
Mathematically it's proven, that the first prime divisor of a non-prime number appears before (or athat tip to jwodder) the square root of said number. This can vastly reduce your searchspace:

for i in xrange(2, math.sqrt(number) + 1):

Peilonrayz correctly added in a comment that the full code can be reformulated as a generator-comprehension using all, which is basically the "most python-y" implementation I've seen yet:

all(number % i for i in range(2, int(number ** 0.5) + 1))



Overall the code is stylistically fine. The Docstring could use a bit of love and the algorithm chosen doesn't lend itself well to python's idea of generators (research this concept, it's key to writing idiomatic and fast python).

Finally: Your java code looks messy to me, since it doesn't conform to the standard egyptian bracing style and is very spacious vertically. 
In the end this seems to boil down to personal preference of vertical space in code.