4.7 String tests
What does this function do?
def validate(name):
if name:
if name[0] != '_' and not name[0].isalpha():
return False
for character in name[1:]:
if character != '_' and not character.isalnum():
return False
return True
return False
Empty names are not good.
validate("")
False
Names that have a single underscore are okay.
validate("_")
True
Names that are digits and letters can be good. These are “alphanumeric.”
validate("income2021")
True
Names that contain underscores and alphanumeric characters can be good.
validate("income_2021")
True
Names that contain other characters are bad.
validate("income-2021")
False
Names that start with a digit are bad.
validate("2021_income"...