Python data type tracking

So, I hope this is the right question ... I recently (today actually) decided to find out how the scripting language is, so I chose Python. Looking at the code, I felt stunned, and soon realized that the reason was because I did not know which data transformations, etc. They continued.

My question is: is there any agreement on what type of data? I come from a stronger background, so I find this rather confusing. Any tips?

+3
source share
2 answers

The usual Python duck typing- based approach is from the old phrase "if it goes crazy like a duck and walks like a duck, it's a duck for me."

, , ( ... ), isinstance .

isinstance ... , Python 2.6 : , - , " ", , ( aka ABC) , , - - .

, , , - :

if hasattr(type(obj), '__call__'): ...

2.6, :

import collections
if isinstance(obj, collections.Callable): ...

. , , , collections.MutableSequence, , .

, ( isinstance) , ABC , , " 4" " " ( ++, !): , .

, , , ; ABC , (ABC - , ), " " , , " isinstance, , , ).

+6

Source: https://habr.com/ru/post/1753641/


All Articles