Tuple passed to function recognised as string
Albert Hopkins
marduk at letterboxes.org
Wed Mar 18 20:09:47 EDT 2009
On Wed, 2009-03-18 at 16:58 -0700, Mike314 wrote:
> Hello,
>
> I have following code:
>
> def test_func(val):
> print type(val)
>
> test_func(val=('val1'))
> test_func(val=('val1', 'val2'))
>
> The output is quite different:
>
> <type 'str'>
> <type 'tuple'>
>
> Why I have string in the first case?
You could have verified this simply by getting rid of the function
altogether:
>>> type(('val1'))
--> <type 'str'>
Hint 1:
>>> type((6))
--> <type 'int'>
Hint 2: It's not the parentheses that define a tuple, it's the comma(s)
>>> x = 'val1',
>>> type(x)
--> <type 'tuple'>
More information about the Python-list
mailing list