0

I tried to check whether a word contain in a string and then perform later functions but it went into the wrong "if".

a = "3,977"

if "割" or "分" in a:
    print("yes")
elif "," in a:
    print(",")
else:
    print("none")

current result:

"yes"

expected result:

","
  • This isn't an exact match to the suggested dupe, but it's close enough IMO. Both turn on the meaning of `'foo' or 'bar'` when compared against something else. – Chris Jun 11 '19 at 02:46

2 Answers2

1

Change

if "割" or "分" in a:

into

if "割" in a or "分" in a:
Ellisein
  • 650
  • 3
  • 12
1

Try this:

a = "3,977"

if any(s in a for s in "割分"):
    print("yes")
elif "," in a:
    print(",")
else:
    print("none")
Rick supports Monica
  • 38,813
  • 14
  • 65
  • 113