Think it like this. We have this code in Python :-

def add(a, b):
    return a + b

Here we are taking two arguments a, b and then returning a + b. But we can pass 
in instance of any class like str, int, float, dict, user-defined class, etc. 
But we only want to add int here. Here we can modify it to be,

def add(a, b):
    if type(a) == int and type(b) == int:
        return a +b
    raise Exception("Error")

In this example it's pretty easy to check if the arguments are int. But in real 
world programs as the functions become bigger and bigger it's very difficult to 
check arguments using an if statement.  Therefore why not let the user specify 
what parameter types are gonna be? Like,

def add(int a, int b):
    return a + b

If instance of a different class is passed in then raise a TypeError perhaps? 
If parameter types are not given then let the parameter accept any kind of 
class instance.

This kind of functionality will minimize a lot of if statements related to 
parameter types and arguments.

Thanking you,
With Regards
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/MVUE5CVE2KXCA6B3TEBUOOFGKRT2HRNK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to