Python: can't assign to literal

后端 未结 8 2263
旧时难觅i
旧时难觅i 2020-11-29 10:43

My task is to write a program that asks the user to enter 5 names which it stores in a list. Next, it picks one of these names at random and declares that person as the winn

8条回答
  •  旧巷少年郎
    2020-11-29 10:56

    I got the same error: SyntaxError: can't assign to literal when I was trying to assign multiple variables in a single line.

    I was assigning the values as shown below:

        score = 0, isDuplicate = None
    

    When I shifted them to another line, it got resolved:

        score = 0
        isDuplicate = None
    

    I don't know why python does not allow multiple assignments at the same line but that's how it is done.

    There is one more way to asisgn it in single line ie. Separate them with a semicolon in place of comma. Check the code below:

    score = 0 ; duplicate = None
    

提交回复
热议问题