I can't reproduce the behavior you've described. The following Python code exercises all three examples presented in your question:
from xml.etree import ElementTree as etree
data = """
<Document>
<Section>
<Section>
<Section SectionNumber="3.1.1">
This is a test.
</Section>
</Section>
</Section>
</Document>
"""
tree = etree.fromstring(data)
print("Test 1")
i = 1
num = "3.1." + str(i)
if num == "3.1.1":
print("correct")
print()
print("Test 2")
num = "3.1.1"
for content in tree.findall(
".//Section/Section/Section[@SectionNumber='{}']".format(num)
):
print("correct")
print()
print("Test 3")
i = 1
num = "3.1." + str(i)
for content in tree.findall(
".//Section/Section/Section[@SectionNumber='{}']".format(num)
):
print("correct")
print()
Running the above code produces:
Test 1
correct
Test 2
correct
Test 3
correct
If you run this code and get different results, or if you can update your question to include a complete, runnable example that produces the behavior you've described, I would be happy to take a closer look.