other python ideas

Stephen Robert Norris srn at fn.com.au
Tue May 23 15:32:31 CEST 2000


In article <392A7F84.A3D5F34A at muc.das-werk.de>, Thomas Thiele
<thiele at muc.das-werk.de> wrote:
> function overloading is a goog idea. It's really the only thing I miss
> in python. But then it must be possible to check different data-types
> (like in C++).
> 
> def foo(   (int)a  ):
>     print a, "is a int"
> 
> def foo(   (float)a  ):
>     print a, " is a float"
> 
> def foo( a ):
>     print "I'm not interested in the type of a. I'm the really true
> pythonfuction."

The Python way would be:

def foo(a):
	if type(a) == type(1):	# Or use the types module.
		print "%d is an int" % a
	elif type(a) == type (0.1):
		print "%f is a float" % a
	...
	else:
		print 'Beats me'

	Stephen



More information about the Python-list mailing list