python print string format code example

Example 1: python format float

>>> x = 13.949999999999999999
>>> x
13.95
>>> g = float("{:.2f}".format(x))
>>> g
13.95
>>> x == g
True
>>> h = round(x, 2)
>>> h
13.95
>>> x == h
True

Example 2: formatted string python

# Newer f-string format
name = "Foo"
age = 12
print(f"Hello, My name is {name} and I'm {age} years old.")
# output :
# Hello, my name is Foo and I'm 12 years old.

Example 3: python print format

print(f'I love {Geeks} from {Portal}')

Example 4: print python format

print('{} {}'.format('one', 'two'))

Example 5: print python format

'{} {}'.format('one', 'two')

Example 6: print format python

print('{:0.3f} {:0.3f}'.format(y, z))

Tags:

Misc Example