Skip to Content
Learn Python by Building Data Science Applications
book

Learn Python by Building Data Science Applications

by Philipp Kats, David Katz
August 2019
Beginner
482 pages
12h 56m
English
Packt Publishing
Content preview from Learn Python by Building Data Science Applications

F-strings

F-strings are relatively new features of Python. They were released in version 3.6 and are both elegant and faster to execute because everything is computed on the go. Here is one example (note the letter f before the starting single quote symbol):

>>> adj = ‘beautiful'>>> f'Hello {adj} world!'Hello beautiful world

Everything inside the curly brackets is actually executable code. Inside this brackets, you can use arithmetic or even run functions:

>>> N = 99>>> f'{N-1} bottles of milk on the wall.''98 bottles of milk on the wall.'>>> name = 'pHILIPP'>>> f'Hello mr{name.title()}''Hello mr. Phillipp'
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python for Data Science

Python for Data Science

Yuli Vasiliev
Introduction to Machine Learning with Python

Introduction to Machine Learning with Python

Andreas C. Müller, Sarah Guido

Publisher Resources

ISBN: 9781789535365Supplemental Content