Error message: Unused Variable

后端 未结 1 449
一个人的身影
一个人的身影 2021-01-29 10:21

So, I\'m currently learning python and I recently created a script that contains two functions, one that creates an account for the user and another that logs the user into thei

1条回答
  •  逝去的感伤
    2021-01-29 11:12

    VS code here just reminds you that you have declared a variable Li but didn't use anywhere further. You are assigning your Li variable True or False value, but what is the practical need for that? Because you currently don't associate any further logic with Li variable, you can simply omit it for now:

    if accounts[user2] == pass2:
        return "You are now logged in"
    else:
        return "Try again, your username and password was incorrect"
    

    However, if you will add a real use-case for your variable further, warning from VS code will disappear as well, for example:

    if accounts[user2] == pass2:
        Li = True
        return "You are now logged in"
    else:
        Li = False
        return "Try again, your username and password was incorrect"
    
    if Li:
        doSomeStuff()
    

    0 讨论(0)
提交回复
热议问题