0
if Region != " " & State != " " & Sku != " ":

TypeError: unsupported operand type(s) for &: 'str' and 'str'

for single string I got it, but for multiple it shows above error

Thanks in advance

DirtyBit
  • 16,613
  • 4
  • 34
  • 55
Ashok
  • 327
  • 2
  • 4
  • 12
  • the issue isnt with the individual conditions, but with how you're joining them together. python uses `and` for logical AND. Also, parenthesis makes conditions clear. – Paritosh Singh Mar 14 '19 at 10:51
  • 2
    FWIW, these strings are not empty. They contain a single whitespace. An empty string is `''` or `""`. – DeepSpace Mar 14 '19 at 10:52
  • In any case check https://stackoverflow.com/questions/8556206/what-does-mean-in-python that will help you understand how the operator is used – Xantium Mar 14 '19 at 10:54

3 Answers3

3

As DeepSpace points out, your strings are not empty. Consider:

if Region.strip() != "" and State.strip() != "" and Sku.strip() != "":

Also, you may want to use lower case variable names, as it is considered good practice.

VdG
  • 31
  • 2
2

Use and instead of &.

  if Region != " " and State != " " and Sku != " ":
Usman
  • 1,983
  • 15
  • 28
-1

In python, you can evaluate strings as a boolean. It returns True if its no empty and it returns True if its empty. So you have to code this:

if not Region and not State and not Sku: