Here is a practical example ...
def get_int():
"""this function will loop until an integer is entered"""
while True:
try:
# return breaks out of the endless while loop
return int(raw_input("Enter an integer: "))
except ValueError:
print("Try again, value entered was not an integer.")
myinteger = get_int()
print("You entered %d" % myinteger)
For Python3 use:
return int(input("Enter an integer: "))