Q:

python string.count(substring) does not work

I have two variables containing string
String1 = """Mon Jun 01 10:43:11 '<rdp> RL_10.10.45.174' from im13258@10.111.0.57 as itssinteladmin@win_kwcstst_10.10.45.174
"""

String2 = """Mon Jun 01 12:29:09 '<rdpDirect> KDCSISSZ1\\ITSSINTELADMIN@win_kdcsissz1_172.16.3.66
"""

I have to search if the substring "ITSSINTELADMIN" or "itssinteladmin" is present in both strings
Surprisingly, the below code not able to find proper value
pkdc = """ Mon Jun 01 10:43:11 '<rdp> RL_10.10.45.174' from im13258@10.111.0.57 as itssinteladmin@win_kwcstst_10.10.45.174"""

mkdc = """Mon Jun 01 10:42:27 '<rdpDirect> KWCSTST\ITSSINTELADMIN@win_kwcstst_10.10.45.174"""

pkdc.count("ITSSINTELADMIN" or "itssinteladmin")
mkdc.count("ITSSINTELADMIN" or "itssinteladmin")

pkdc.count returns 0 i.e. no match whereas mkdc.count returns 1 i.e. match found
I am probably doing something wrong!

A:

First "ITSSINTELADMIN" or "itssinteladmin" is evaluated as "ITSSINTELADMIN" only, because as its bool value is True (non-empty string) it doesn't keep the second part, so as you look for the uppercase version in each string, it's normal that it is only found in mkdc version
s = "ITSSINTELADMIN" or "itssinteladmin"
print(s)  # ITSSINTELADMIN
print(s in pkdc)  # False
print(s in mkdc)  # True

To count for multiple strings you ay iterate over the possibilities
s = ["ITSSINTELADMIN", "itssinteladmin"]
print(s)  # ['ITSSINTELADMIN', 'itssinteladmin']

res = [pkdc.count(item) for item in s]
print(res)  # [0,1]
res = [mkdc.count(item) for item in s]
print(res)  # [1,0]

You could use sum to get one value only, and get the total count of every word you look for

