(Dec-03-2017, 04:06 PM)j.crater Wrote: It is a way to format strings in Python. Similar to using % notation in Python 2, C language etc. So in your case {} gets substituted with value of M, which is calculated with the formula you provided.
Here you can find documentation on it and a few simple examples:
https://docs.python.org/3.4/library/stri...t-examples
Thanks very much!
That was exactly what I needed.
Sorry, I should have RTFM first. :)
- O
(Dec-03-2017, 04:11 PM)snippsat Wrote: It's called string formatting.
The evolution of string formatting.
>>> M = 100 >>> # old don't use >>> print('M = %d' % M) M = 100 >>> >>> # Python 2.6 we get format() >>> print('M = {}'.format(M)) M = 100 >>> >>> # Python 3.6 we get f-string >>> print(f'M = {M}') M = 100f-string is the future,but format() will be used for a long time.
f-string can take expressions here calculate and upper():
>>> a = 10 >>> b = 20 >>> s = 'correct' >>> print(f'The sum of a {a} and b {b} is {a+b} {s.upper()}') The sum of a 10 and b 20 is 30 CORRECTMore about format() PyForamt.
Excellent! I've copied these for reference.
- O