How to get type of object's attribute in python

Home / Uncategorized / How to get type of object's attribute in python

Question:
assume I have the following class:class myClass():def __init__(self, number):self.myStr = "bla"
self.myInt = number * 3

how do I get the the attributes types? I mean I want to get the following list: [‘str’,’int’]?

I also want it to work on derived classes.

Thanks a lot 🙂


Answer:
Use the type() function. You can even use it to print out the variable type like this:print(type(variable_name))
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *