[Tutor] Convert String to Int
kent37 at tds.net
Mon Jan 19 21:11:16 CET 2009
On Mon, Jan 19, 2009 at 1:36 PM, wesley chun <wescpy at gmail.com> wrote:
>> if type(x) == int: # check its an integer
> i also understand that it's "isinstance(x, int)" should be used
> instead of the above or "if type(x) is int" but i'm running a blank as
> to why at this exact moment... perhaps it's an all-C function?
If x is an instance of a subclass of Y, 'type(x) == Y" and "type(x) is
Y" will fail; isinstance(x, Y) will succeed. Generally it's preferable
to allow subclasses so isinstance() is preferred.
More information about the Tutor