string formatting

🏠

Printing strings with variable values, i.e string formatting (PEP-3101), has become incredibly easy in Python 3. Simply precede a string with f.

1 a = 123
2 s = f'value of a: {a}'
3 print(s)

Output:

1 value of a: 123
1 for i in range(10):
2   print(f"{10**i:>20}")

Output:

 1                    1
 2                   10
 3                  100
 4                 1000
 5                10000
 6               100000
 7              1000000
 8             10000000
 9            100000000
10           1000000000