import re
p = re.compile(r'(\b\d+(?:\.\d+)?(?:\spercent|\%))')
test_str = "The grades of the two students improved by 5.2% and 5.4% it was 5 percent or 1.2%."
result = re.sub(p, "__PERCENTAGE__", test_str)
print (result)