Answers for "python f string right justify"

10

f string float format

>>> a = 10.1234
>>> f'{a:.2f}'
'10.12'
Posted by: Guest on July-21-2020
1

How to justify a string in Python f-strings

s1 = 'Python'
s2 = 'ython'
s3 = 'thon'
s4 = 'hon'
s5 = 'on'
s6 = 'n'

print(f'{s1:>6}')
print(f'{s2:>6}')
print(f'{s3:>6}')
print(f'{s4:>6}')
print(f'{s5:>6}')
print(f'{s6:>6}')
...
Python
 ython
  thon
   hon
    on
     n

....
Posted by: Guest on August-30-2021
-2

python f-string padding

#!/usr/bin/env python3

name = 'Peter'
age = 23

print('%s is %d years old' % (name, age))
print('{} is {} years old'.format(name, age))
print(f'{name} is {age} years old')
Posted by: Guest on July-08-2020

Python Answers by Framework

Browse Popular Code Answers by Language