the common way is
At the end of the link there is also link to other resources why checking for type is against python principles/design patterns. You probably have heard that it's easier to ask for forgiveness than permission and "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck" (https://docs.python.org/3.6/glossary.html , check EAFP and duck-typing) https://en.wikipedia.org/wiki/Duck_typing
var = 5 print(isinstance(var, int))note that you can supply multiple types as second argument
var = 5 var2 = 1.2 var3 = 'some text' print(isinstance(var, (int, float))) print(isinstance(var2, (int, float))) print(isinstance(var3, (int, float)))read https://docs.quantifiedcode.com/python-a...tance.html or https://stereochro.me/ideas/type-vs-isinstance why
isinstance()
is preferable than type()
At the end of the link there is also link to other resources why checking for type is against python principles/design patterns. You probably have heard that it's easier to ask for forgiveness than permission and "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck" (https://docs.python.org/3.6/glossary.html , check EAFP and duck-typing) https://en.wikipedia.org/wiki/Duck_typing
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs