0
How does .format() work?
I don't really get it
6 Antworten
+ 6
For example you can 'copy paste' variables into your output.
age = 18
print('I am {} years
old!'.format(age))
-> I am 18 years old!
+ 7
Just so you know, since Python 3.6 f-strings were introduced, making the whole formatting issue a looooot easier, cleaner and more intuitive :)
But if you still need a lesson the .format() way, here it is:
https://www.sololearn.com/learn/Python/2455/?ref=app
+ 3
Like.....
myInt = 5
f"some string{myInt}” or "some string %d” myInt
+ 2
...and see here https://pyformat.info/
+ 2
Kuba Siekierzyński Yes, but its always useful to know for who dont want switch to py3 😁