What is the best (idiomatic) way to check the type of a Python variable? [duplicate]

This question already has answers here: What are the differences between type() and isinstance()? (7 answers) Closed 9 years ago. I need to know if a variable in Python is a string or a dict. Is there anything wrong with the following code? if type(x) == type(str()): do_something_with_a_string(x) elif type(x) == type(dict()): do_somethting_with_a_dict(x) else: raise … Read more

Class type check in TypeScript

In ActionScript, it is possible to check the type at run-time using the is operator: var mySprite:Sprite = new Sprite(); trace(mySprite is Sprite); // true trace(mySprite is DisplayObject);// true trace(mySprite is IEventDispatcher); // true Is it possible to detect if a variable (extends or) is a certain class or interface with TypeScript? I couldn’t find … Read more