Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A variant is useful to update two (or more) dependent variables in one go without having to introduce temporary variables. For example to calculate the greatest common divisor using the Euclidean algorithm:

    def gcd(a, b):
        while b > 0:
            a, b = b, a % b
        return a


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: