formatted string python 3 code example
Example 1: f string in python
name = "John Smith"
print(f"Hello, {name}")
name = "John Smith"
print("Hello, {}".format(name))
Example 2: formatted string python
name = "Foo"
age = 12
print(f"Hello, My name is {name} and I'm {age} years old.")
Example 3: python f string
>>> name = "Eric"
>>> age = 74
>>> f"Hello, {name}. You are {age}."
'Hello, Eric. You are 74.'
Example 4: python fstring
age = 12
name = "Simon"
print(f"Hi! My name is {name} and I am {age} years old")
Example 5: new python string formatting
>>> f'Hello, {name}!'
'Hello, Bob!'
Example 6: str.format python 3
print("Sammy ate {0:f} percent of a {1}!".format(75, "pizza"))