.format and f format in python code example
Example 1: python f string
"""
An f-string stands for 'function-string' it's just used to work with
strings more appropiately, they do the exact same job as concantenating
strings but are more efficient and readable.
"""
Age = "25"
print("I am "+Age+" years old.")
Age = 25
print(f"I am {Age} years old.")
Age = "25"
print("I am {} years old.".format(Age))
Age = "25"
Name = "Jeff"
print("I am {} years old, and my name is {}.".format(Age,Name))
Example 2: python f string
import math
print('[[fill]align] | f\'{"text":10}\' | ', f'{"text":10}')
print('[[fill]align] | f\'{"text":>10}\' | ', f'{"text":>10}')
print('[[fill]align] | f\'{"text":^10}\' | ', f'{"text":^10}')
print('[[fill]align] | f\'{"text":#>10}\' | ', f'{"text":#>10}')
print('[[fill]align] | f\'{"text":#<10}\' | ', f'{"text":#<10}')
print('[[fill]align] | f\'{"text":#^10}\' | ', f'{"text":#^10}')
print('[[fill]align] with numbers | f\'{12345:0=10}\' | ', f'{12345:0=10}')
print('[[fill]align] with numbers | f\'{-12345:0=10}\' | ', f'{-12345:0=10}')
print('[[fill]align] with numbers | f\'{12345:010}\' | ', f'{12345:010}')
print('[[fill]align] with numbers | f\'{-12345:010}\' | ', f'{-12345:010}')
print('[.precision] | f\'{math.pi:.2f}\' | ', f'{math.pi:.2f}')
print('[grouping_option] | f\'{1000000:,.2f}\' | ', f'{1000000:,.2f}')
print('[grouping_option] | f\'{1000000:_.2f}\' | ', f'{1000000:_.2f}')
print('[sign] (+/-) | f\'{12345:+}\' | ', f'{12345:+}')
print('[sign] (+/-) | f\'{-12345:+}\' | ', f'{-12345:+}')
print('[sign] (+/-) | f\'{12345:+10}\' | ', f'{12345:+10}')
print('[sign] (+/-) | f\'{-12345:+10}\' | ', f'{-12345:+10}')
print('[sign] (+/-) | f\'{12345:+010}\' | ', f'{12345:+010}')
print('[sign] (+/-) | f\'{-12345:+010}\' | ', f'{-12345:+010}')
print('[b] (binary) | f\'{10:b}\' | ', f'{10:b}')
print('[o] (octal) | f\'{10:o}\' | ', f'{10:o}')
print('[x] (hexadecimal) | f\'{100:x}\' | ', f'{100:x}')
print('[#b] (with notation base) | f\'{10:#b}\' | ', f'{10:#b}')
print('[#0] (with notation base) | f\'{10:#o}\' | ', f'{10:#o}')
print('[#x] (with notation base) | f\'{10:#x}\' | ', f'{10:#x}')
print('[e] (scientific notation) | f\'{345600000000:e}\' | ', f'{345600000000:e}')
print('[c] (character type) | f\'{65:c}\' | ', f'{65:c}')
print('percentage (multiply by 100) | f\'{0.25:0%}\' | ', f'{0.25:0%}')
print('percentage (multiply by 100) | f\'{0.25:.0%}\' | ', f'{0.25:.0%}')