[Tutor] Type Checking:

Sheila King sheila@thinkspot.net
Sat, 03 Mar 2001 09:34:53 -0800


On Sat, 3 Mar 2001 08:10:48 -0900, Tim Johnson <tim@johnsons-web.com>  wrote
about [Tutor] Type Checking::

:Hello:
:	I need to be able to test the type of a variable:
:Consider the following code:
:# code begins
:>>> str = 'hello'
:>>> type(str)
:<type 'string'>
:>>> if type(str) == 'string':         
:...   print "it's a string"
:... else:
:...   print "I don't know how to type"
:... 
:I don't know how to type
:# code ends
:
:How do I get this code to return 
:"it's a string"

This problem is interesting to me. I've been playing with it for a few
minutes, now. I'm not clear on exactly how one can work with the objects that
the type() function returns.

However, I did manage to do, at least this:

>>> str = 'hello'
>>> type(str)
<type 'string'>
>>> str2 = 'bye!'
>>> if type(str) == type(str2):
	print "type match"
else:
	print "no type match"

type match
>>> 

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/