Context
I'm not used to parameter specifications when declaring a function in python.
In the following example, we specify the parameters x
and y
to be of type int
:
def add(x: int, y: int) -> int:
return x + y
I'm using numpy to initialize a 2D array of 0s and I'm not sure how to specify a 2D array as my parameter. Here's what I have:
import numpy as np
def fillWithOnes(array: type([[]])) -> None:
for row in array:
for i in range(0, len(row)):
row[i] = 1
table = np.zeros((5,5))
fillWithOnes(table)
print (table)
Question
Is type([[]])
on line 3 correct? I've been having trouble finding an answer in python's Typing docs here.
I also noticed that I can specify the parameter, array
to be an int
and the code still works. Which leads me to my second question: Is typing purely for third party tools; maybe general sanity and readability as well?
Thanks