At 09:40 PM 12/5/2006, wesley chun wrote: > > > How can I check if a variable is an integer? > > > > Luke and John have answered your question, but we should also ask, why > > do you want to do that? Explicit type testing is a code smell, perhaps > > there is a better way to do what you want. > > >- another way of doing it is: type(aVar) is int (which is faster than >using "==") >- if you want to check for ints and all subclasses of int: >isinstance(aVar, int) >- if you want to check for ints, longs, and all subclasses: >isinstance(aVar, (int, long)) > >because python is strongly yet duckly-typed, there are circumstances >where you want to do some self introspection to find out what kind of >objects you've got. this obviates the need for Python to support >multiple signatures, function overloading, etc. with that said, >however, it would also be a good idea to see what your application is >and determine if this kind of checking is warranted.
Very interesting. But what is "duckly-typed"? I'm so dumb I can't distinguish between a typo and a technical term.. Dick Moores _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor