Home > OS >  Python How To Assign 2 Variables in One Part(?)
Python How To Assign 2 Variables in One Part(?)

Time:01-29

Im sorry ı couldn't write decent title. But let me explain.

a list that holds ten variable
list[0] = tshirt
but if user search t-shirt in that list, program should accept it as tshirt.
What Im asking is, can I say

list[0] = "tshirt" or "t-shirt"

if not, must I do that manually or is there any way to do this?

thanks.

CodePudding user response:

You can either check for two values using the in operator:

list[0] in ("tshirt", "t-shirt")

or check for "tshirt" only but replace all occurrences of - with empty spaces, so that both "tshirt" and "t-shirt" (changed to "tshirt") actually match.

list[0].replace('-', '') = "tshirt" 

Check the Python demo.

CodePudding user response:

I did not fully understand but, you want to ignore the "-" character?

if list[0].replace('-','')=="tshirt":
    True

That would be very bad use. You should better explain what you need.

  • Related