Differences between revisions 1 and 3 (spanning 2 versions)
Revision 1 as of 2019-01-29 04:27:19
Size: 110
Editor: PieterSmit
Comment:
Revision 3 as of 2019-01-29 04:32:18
Size: 413
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from Python/FstringFromating
Line 3: Line 4:
   * an f-string is created by prefixing the string with a f e.g. '''
f"this is a f-string"
     '''

== Examples of f-strings ==
 * numbers '''
a= 10.1234
>>> f'{a:.2f}'
'10.12'

>>> f'{a*1000:,.2f}'
'10,123.40'
'''
 * date '''

'''

Python Fstring formatting

  • f - string is the latest python string formatting addition, added in 3.5
    • an f-string is created by prefixing the string with a f e.g.

f"this is a f-string"

Examples of f-strings

  • numbers

a= 10.1234 >>> f'{a:.2f}' '10.12'

>>> f'{a*1000:,.2f}' '10,123.40'

  • date

Python/FStringsAndFormatting (last edited 2022-11-20 07:49:57 by PieterSmit)