python string format with { code example
Example 1: python string format
string_a = "Hello"
string_b = "Cena"
print("{0}, John {1}"
.format(string_a, string_b))
print("{greeting}, John {last_name}"
.format(greeting=string_a, last_name=string_b))
Example 2: python .format
Name = 'Tame Tamir'
Age = 14
Formatted_string = 'Hello, my name is {name}, I am {age} years old.'.format(name=Name,age=Age)
print(Formatted_string)
Example 3: string formatting in python
name = "Foo"
age = 12
print(f"Hello, My name is {name} and I'm {age} years old.")
Example 4: String Formatting with the % Operator
>>> name = 'Bob'
>>> 'Hello, %s' % name
"Hello, Bob"