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. – ChrisGPT was on strike Jun 11 '19 at 02:46

2 Answers2

1

Change

if "割" or "分" in a:

into

if "割" in a or "分" in a:
Ellisein
  • 878
  • 6
  • 17
1

Try this:

a = "3,977"

if any(s in a for s in "割分"):
    print("yes")
elif "," in a:
    print(",")
else:
    print("none")
Rick
  • 43,029
  • 15
  • 76
  • 119