F-Strings decilamal places code example
Example 1: F-Strings decilamal places
import datetime
now = datetime.datetime.now()
print(f'{now:%Y-%m-%d %H:%M}')
Example 2: F-Strings decilamal places
a = 300
print(f"{a:x}")
print(f"{a:o}")
print(f"{a:e}")
Example 3: F-Strings decilamal places
s1 = 'a'
s2 = 'ab'
s3 = 'abc'
s4 = 'abcd'
print(f'{s1:>10}')
print(f'{s2:>10}')
print(f'{s3:>10}')
print(f'{s4:>10}')
Example 4: F-Strings decilamal places
for x in range(1, 11):
print(f'{x:02} {x*x:3} {x*x*x:4}')
Example 5: F-Strings decilamal places
val = 12.3
print(f'{val:.2f}')
print(f'{val:.5f}')