1# Newer f-string format
2name = "Foo"
3age = 12
4print(f"Hello, My name is {name} and I'm {age} years old.")
5# output :
6# Hello, my name is Foo and I'm 12 years old.
1string_a = "Hello"
2string_b = "Cena"
3
4# Index based:
5print("{0}, John {1}"
6 .format(string_a, string_b))
7# Object based:
8print("{greeting}, John {last_name}"
9 .format(greeting=string_a, last_name=string_b))
10
1Name = 'Tame Tamir'
2Age = 14
3
4Formatted_string = 'Hello, my name is {name}, I am {age} years old.'.format(name=Name,age=Age)
5# after the formatting, the variable name inside the {} will be replaced by whatever you declare in the .format() part.
6print(Formatted_string) # output = Hello, my name is Tame Tamir, I am 14 years old.
1#The {} are replaced by the vairables after .format
2new_string = "{} is string 1 and {} is string 2".format("fish", "pigs")