0
Python
Please I need explanation on how to make the attributes of a function to be receiving a class object and how to check the type of class the object is before working with it.. thank you
2 Answers
+ 2
Abdullah
I think Explanation is given here.
https://www.sololearn.com/learning/2467/
+ 1
As far as I can understand your question,
To check the type of any object use the type() function.
Suppose you've a custom class, 'Animal'. Now you've created a function which takes an input. To check if the input is an object of Animal class, write,
def func(x):
if not type(x)==Animal:
return None
# or raise some error
......
Or,
def func(x):
asser type(x) is Animal
# if x is not an object of class Animal
# then it will raise an Assertion Error
......
# In Python everything is an object, so take input as you normally do.