Syntax question
Klaus Jantzen
k.d.jantzen at mailbox.org
Sun Aug 16 04:12:04 EDT 2020
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.
More information about the Python-list
mailing list