0

I am a beginner in programing and I am trying to assign multiple values to the "contains" variable but I keep getting: "TypeError: 'in ' requires string as left operand, not tuple." Can anybody tell me what this means and how to solve it? Here is the program (tkinter):

def myClick():
password = e.get()
contains = "1", "2"

if contains in password:
    myLabel = Label(root, text= "Password Level is Strong")
    myLabel.pack()
2
  • You can use if any(x in password for x in matches): where matches is ['1','2'] Commented Jun 25, 2021 at 16:26
  • @lucal No problem. I thought that you were looking for something like what @ Sujay said so I deleted my comment :D. Commented Jun 25, 2021 at 16:34

1 Answer 1

0

Python is giving you this message because you are trying to compare tuple with string but you need to compare string with tuple.. for example with your code:

if password in contains:
    myLabel = Label(root, text= "Password Level is Strong")
    myLabel.pack()

and i advice you to use 'for loop' if you want to work with tuples or lists..

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.