python print formatted string code example
Example 1: formatted string python
name = "Foo"
age = 12
print(f"Hello, My name is {name} and I'm {age} years old.")
Example 2: formatting in python
>>> name = "John"
>>> age = 19
>>> language = "python"
>>> print(f"{name} of age {age} programs in {language}")
John of age 19 programs in python
>>> print("%s of age %d programs in %s" %(name, age, language))
John of age 19 programs in python
>>> print("{} of age {} programs in {}".format(name, age, language))
John of age 19 programs in python
>>> print("{2} of age {1} programs in {0}".format(name, age, language))
python of age 19 programs in John
Example 3: python print format
print(f'I love {Geeks} from {Portal}')
Example 4: print python format
print('{} {}'.format('one', 'two'))
Example 5: print format python
print('{:0.3f} {:0.3f}'.format(y, z))