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?

Because (<any expression>) == <any expression>.
Perhaps you meant ('val1',).

"Parenthesized forms
A parenthesized form is an optional expression list enclosed in parentheses:

parenth_form ::=  "(" [expression_list] ")"

A parenthesized expression list yields whatever that expression list yields: if the list contains at least one comma, it yields a tuple; otherwise, it yields the single expression that makes up the expression list.

An empty pair of parentheses yields an empty tuple object.
"

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to