Skip to content

Instantly share code, notes, and snippets.

@rcanepa
Created August 30, 2017 01:58
Show Gist options
  • Select an option

  • Save rcanepa/f77c0edd432ac070a7ad68d3204a6eb5 to your computer and use it in GitHub Desktop.

Select an option

Save rcanepa/f77c0edd432ac070a7ad68d3204a6eb5 to your computer and use it in GitHub Desktop.
String Formatters in Python 3
age = 31.67
"Renzo ist ein {0} {1}, der in {country:*^20} wohnt. Er ist {2:.1f} Jahre alt.".format("sympatischer", "Mensch", age, country="Chile")
=> 'Renzo ist ein sympathischer Mann, der in *******Chile******** wohnt. Er ist 31.7 Jahre alt.'
for i in range(3,13):
print("{:6d} {:6d} {:6d}".format(i, i*i, i*i*i))
=>
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729
10 100 1000
11 121 1331
12 144 1728
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment