Python Return Syntax Error

前端 未结 2 1350
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 02:02
def list_function(x):
    return x[1] += 3

I want to do this, but apparently I can\'t. I understand I can do this

x[1] += 3
return x
         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-22 03:02

    From documentation -

    return_stmt ::= "return" [expression_list]

    The return statement can only be followed by expressions. expression_list is -

    expression_list ::= expression ( "," expression )* [","]

    But x[1] += 1 is an augmented assignment statement , and as such you cannot have that after return .

提交回复
热议问题