A mother. A baby. Two burglars

Ican hear the wood of the floor groans as it disturbs the tranquility in my room. It is three am — known as the devil’s hour to believers. The hour when the veil is thin between the natural and…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




3 Ways to Explore a Python Object

When we get a reference of a Python object, how can we know the information about it? Of course, we can read its source code. However, sometimes we don’t have enough time to read it or even we just get this object from an API and cannot access its source code.

This post will introduce three ways to have a quick check of a Python object.

First of all, when we get an object, we can check which type it belongs to by type() method.

Since the type() method returns an object’s type, it can be used to compared two types.

Note: In the above example, we compared type(b)==int and got a True. If we compare type(b)==type(int), a False will be printed. Because the type of int is type.

With the help of the types module, we can check more complex types:

For inherited classes, using the isinstance() method is a very convenient way to check their inheritance relationship.

Add a comment

Related posts:

i have nothing to write about

i wish i had something to write about on this website.. “i have nothing to write about” is published by All Over.

Finding the Facts within Social Media News

The role that social media plays today has increasingly heightened with many people turning toward their favorite social media platform to find the most relevant news. We are constantly absorbing…

Will my story be heard outside of my own echo chamber?

I am making a documentary because I’m worried about leaving a legacy for today’s young people we might regret, but will its reach and success depend on an unaccountable algorithm? I am a Gen X-er who…