Python: can't assign to literal

后端 未结 8 2256
旧时难觅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 11:14

    Just adding 1 more scenario which may give the same error:

    If you try to assign values to multiple variables, then also you will receive same error. For e.g.

    In C (and many other languages), this is possible:

    int a=2, b=3;
    

    In Python:

    a=2, b=5
    

    will give error:

    can't assign to literal

    EDIT:

    As per Arne's comment below, you can do this in Python for single line assignments in a slightly different way: a, b = 2, 5

提交回复
热议问题