-5
vendor = ' AFL TELECOMMUNICATIONS '
' AFL TELECOM*' in vendor

Running this code gives FALSE when I expected it to give TRUE. It seems that the 'in' clause is not seeing the asterix '*' as wild card. Any suggestions how to make this work? Thanks!

Chadee Fouad
  • 2,630
  • 2
  • 23
  • 29
  • 6
    The `in` operator does not support wildcards. You might want to use regular expressions or another text pattern matching. BTW `' AFL TELECOM' in …` might also be a solution if the wildcard is at the end. – Klaus D. Jan 20 '20 at 16:10
  • 1
    In this case, where the wildcard is at the end of the test string and should match exactly one character, you can do it with `in`: `' AFL TELECOM' in vendor[:-1]` tests that `vendor` has a substring `' AFL TELECOM'` followed by any character (i.e. the substring is not at the end). – kaya3 Jan 20 '20 at 16:12
  • 1
    Does this answer your question? [Wildcard matching a string in Python regex search](https://stackoverflow.com/questions/1996482/wildcard-matching-a-string-in-python-regex-search) – C_Z_ Jan 20 '20 at 16:12

1 Answers1

2

You're gonna want to use a regular expression instead.

import re

vendor = 'AFL TELECOMMUNICATIONS'

if re.search('AFL TELECOM.*', vendor):
    print("Match")
else:
    print("No Match")
Nizar
  • 2,034
  • 1
  • 20
  • 24