Hi,

the other day I came across the book "Classic Computer Science Problems in Python" by David Kopec.

The function definitions in the examples  like

=====
def fib2(n: int) -> int:
    if n < 2:  # base case
        return n
    return fib2(n - 2) + fib2(n - 1)  # recursive case


if __name__ == "__main__":
    print(fib2(5))
    print(fib2(10))

=====

use a syntax that I have never seen on this list or in other publications.

My questions:

Is that new?

Is is 'recommended' to use this is the future?

I can only see a certain advantage of using this type of function definition in resp. to the documentation, as it does not provide an automatic check of the type of the argument(s) or of the result as in Java.

--

K.D.J.

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to