format.strformater matplotpib code example
Example 1: formatting in python
>>> name = "John"
>>> age = 19
>>> language = "python"
>>> print(f"{name} of age {age} programs in {language}")
John of age 19 programs in python
>>> print("%s of age %d programs in %s" %(name, age, language))
John of age 19 programs in python
>>> print("{} of age {} programs in {}".format(name, age, language))
John of age 19 programs in python
>>> print("{2} of age {1} programs in {0}".format(name, age, language))
python of age 19 programs in John
Example 2: method for format age in python
def format_age(s):
chars = list(s)
digit_chars = [c for c in chars if c.isdigit()]
return int("".join(digit_chars))