![[Snippet] If Object == Datatype in Python ohne types-Modul](http://city-insider.de/wp-content/uploads/python-logo.png)
[Snippet] If Object == Datatype in Python ohne types-Modul
An einigen Stellen in eurem Code müsst ihr sicher prüfen ob euer Objekt einen bestimmten Datentyp hat. Dies lässt sich mit dem Modul types realisieren. Types ist zwar ein Standard-Modul, aber mir gefällt die Lösung trotzdem nicht. Wieso sollte ich für so eine einfach Aufgabe extra ein Modul importieren?
Daher nutze ich folgende und meiner Meinung viel einfachere Möglichkeit:
if type([1, 2 ,3]) is list: print True else: print False # >>> True if type([1, 2 ,3]) is tuple: print True else: print False # >>> False if type((1, 2 ,3)) is tuple: print True else: print False # >>> True if type(123) is int: print True else: print False # >>> True if type(123) is str: print True else: print False # >>> False if type('123') is str: print True else: print False # >>> True