Example 1: f string in python
name = "John Smith"
print(f"Hello, {name}")
name = "John Smith"
print("Hello, {}".format(name))
Example 2: python f string
>>> name = "Eric"
>>> age = 74
>>> f"Hello, {name}. You are {age}."
'Hello, Eric. You are 74.'
Example 3: python fstring
age = 12
name = "Simon"
print(f"Hi! My name is {name} and I am {age} years old")
Example 4: python f string
import random
name = input("What is your name? ")
value = int(input(f"Give random value, {name}: "))
multiplier = random.randint(3, 6)
print("Now multiplying your value...")
complete_value = multiplier * value
print(f"Your value is... {complete_value}")
Example 5: python f string
>>> name = "Eric"
>>> age = 74
>>> f"Hello, {name}. You are {age}."
'Hello, Eric. You are 74.'
Example 6: 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%}')