ids = ["XF345_89", "XER76849", "XA454_55"]
x = 0
for id in ids:
if '_' in id:
x = x + 1
print(x)
This was from a coding exercise on a Udemy video I am learning Python from. Obviously the intended output is just '2' and you do this by unindenting the print function, but just curious why the incorrect answer is the way it is?
x
doesn't get increased for it.2 2 3
? If you changex = 0
tox = 1
it does print what you expect.print()
statementid()
is a built-in Python function. You are hiding it with a local variable of the same name here.