The other answers here are correct—you need to guarantee that a has been assigned a value before you try to print it. However, none of the other answers mentioned Python's for ... else construct, which I think is exactly what you need here:
with open('text','r') as f:
for line in f.readlines():
if 'hi' in line:
a='hello'
break
else:
a='value not found'
print a #variable requires outside the loop
The else clause is only run if the for loop finishes its last iteration without break-ing.
This construct seems unique to Python in my experience. It can be easily implemented in languages that support goto, but Python is the only language I know of with a built-in construct specifically for this. If you know of another such language, please leave a comment and enlighten me!
aoutside the loopais not guaranteed to be set by the code.