In Python methods are a bit strange, at least compared to other languages. A function, say in C++, goes something like so:
void foo(int i){
cout << i*2 << "\n";
}
This ensures that the object passed into that function is in fact an integer. However in Python the same function looks like this:
def foo(i):
print i*2
This function doesn't require i
to be an integer, let alone a number. You could even pass in a string. So my question is: what is the general approach for handling this when writing code? Generally speaking, is it better to check the type and throw an error message if used incorrectly or is it preferred to no check at all and assume the correct type has been passed?