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

4th May 2021, 9:27 PM
Abdullah
2 ответов
+ 2
Abdullah I think Explanation is given here. https://www.sololearn.com/learning/2467/
4th May 2021, 9:34 PM
A͢J
A͢J - avatar
+ 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.
5th May 2021, 4:22 AM
Md. Faheem Hossain
Md. Faheem Hossain - avatar