f strings python version code example

Example 1: python f string

>>> name = "Eric"
>>> age = 74
>>> f"Hello, {name}. You are {age}."
'Hello, Eric. You are 74.'

Example 2: python f string

import random
name = input("What is your name? ") #Gets needed input
value = int(input(f"Give random value, {name}: ")) # The {name} means it puts the variable name there
multiplier = random.randint(3, 6)
print("Now multiplying your value...")
complete_value = multiplier * value
print(f"Your value is... {complete_value}") # Same here with complete_value

Tags:

Java Example