Python is the most popular programming language in recent years. Many people know that. But if you ask what are the distinctive advantages of Python? Not everyone can answer that. And there could be many answers.

For me, it would definitely be ‘object introspection’ or ‘type introspection’. While you can find similar features in many other languages, Python offers arguably the most beginner-friendly built-in tools for you to do so.

But first of all, what is object introspection?

It is the ability to examine the type or properties of an object during runtime, and leverage their properties within the code. Here are 4 easy-to-use introspection functions that beginners should learn.

1. type()

Data types are the classification of objects that determine what kinds of operation can be performed on them. For instance, the plus operator + can be applied to integers as well as strings, but they are performed differently.

a = 1 + 1 ## 2
b = 'Hello' + 'World' ## 'HelloWorld'

The former is a summation operation, whereas the latter is concatenation. If you try ‘adding’ 1 + 'Hello' together, you will get an error as this operation is undefined.

Therefore, data types are very important as it affects how an operation is performed. However, data types in Python are a nightmare. This is because there are many various data types from different libraries written by different groups of people with different standards and usages.

#python

4 Easy-to-use Introspection Functions in Python
17.00 GEEK