关于赋值语句中间的逗号的使用
def cmp_ignore_case(s1, s2):
u1=s1.lower(),u2=s2.lower()
if u1<u2:
return -1
elif u1>u2:
return 1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)
上述程序第二行,赋值语句中间使用逗号隔开,运行显示File "index.py", line 2
u1=s1.lower(),u2=s2.lower()
SyntaxError: can't assign to function call。
但是将逗号去掉,u1和u2分行写,如下,便成功运行。不知道原因在哪,是不是因为逗号的使用问题?感谢讲解。
def cmp_ignore_case(s1, s2):
u1=s1.lower()
u2=s2.lower()
if u1<u2:
return -1
elif u1>u2:
return 1
else:
return 0
print sorted(['bob', 'about', 'Zoo', 'Credit'], cmp_ignore_case)