A cheatsheet for string processing in Python.
How to convert a text with percentages to float
Use strip('+%'):
txt = "+77%"
print(float(txt.strip('+%'))/100)
Regular expressions in re.search
Check if a string contains any letter:
re.search('[a-zA-Z]', the_string)
Check if a string contains all — uppercase, lowercase, and numbers:
upcase = re.search(r"[A-Z]", the_string)
lowcase = re.search(r"[a-z]", the_string) nums = re.search(r"[0-9]", the_string) contains_all = all((upcase, lowcase, nums))