May 2017
Intermediate to advanced
270 pages
6h 18m
English
You can add type information to the arguments of a Python function by specifying the type in front of each of the argument names. Functions specified in this way will work and perform like regular Python functions, but their arguments will be type-checked. We can write a max_python function, which returns the greater value between two integers:
def max_python(int a, int b): return a if a > b else b
A function specified in this way will perform type-checking and treat the arguments as typed variables, just like in cdef definitions. However, the function will still be a Python function, and calling it multiple times will still need to switch back to the interpreter. To allow Cython for function call optimizations, we should declare ...
Read now
Unlock full access