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 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 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 = 'Psych4_3.8.3'
age = 23
job = 'programmer'
print("I am %s a %t of age %u", %(name, job, age))
print(f"I am {name} a {job} of age {age}")
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%}')