Lightning talk about f-strings. Presented at PyCascades 2018 in Vancouver.
F-strings @mariatta
View Slide
F-strings?
the new way to format strings
starting in Python 3.6
How?
How?"Hello, %s. You’re %s." % (name, age)
How?"Hello, {name}. You’re {age}.".format(name=name, age=age)"Hello, %s. You’re %s." % (name, age)
How?"Hello, {name}. You’re {age}.".format(name=name, age=age)f"Hello, {name}. You’re {age}.""Hello, %s. You’re %s." % (name, age)
Alternate usage
Alternate usagef"Hello, {name}. You’re {age}."
Alternate usageF"Hello, {name}. You’re {age}."f"Hello, {name}. You’re {age}."
Call a function>>> def to_uppercase(input):... return input.upper()...>>> name = “bart simpson”>>> print(f"Hi {to_uppercase(name)}!")Hi BART SIMPSON!
Format specifiers>>> pycascades = datetime(year=2018, month=1, day=22)>>> print(f"{pycascades:%b %d, %Y}")Jan 22, 2018
F-strings
Faster than str.format
Python 3.6
Free downloadwww.python.org
Build from sourcehttps://docs.python.org/3.6/using/unix.html
Change your OSconsider: MacOS X, Windows 10, fedora 26, ubuntu 17.10