February 2019
Intermediate to advanced
672 pages
16h 50m
English
In Cython, you can declare the type of a variable by prepending the variable with cdef and its respective type. For example, we can declare the i variable as a 16 bit integer in the following way:
cdef int i
The cdef statement supports multiple variable names on the same line along with optional initialization, as seen in the following line:
cdef double a, b = 2.0, c = 3.0
Typed variables are treated differently in comparison to regular variables. In Python, variables are often described as labels that refer to objects in memory. For example, we could assign the value 'hello' to the a variable at any point in the program without restriction:
a = 'hello'
The a variable holds a reference to the 'hello' string. We can also freely ...