0
How does .format() work?
I don't really get it
6 RĂ©ponses
+ 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 đ