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

Format method

A string's format method will inject its arguments into the string, replacing the fields defined by curly braces. A specific field can be defined either by the number (in this case, you just should keep arguments in the same order) or by using keywords. Here are some examples:

  1. The following example has no placement strategy and simple curly brackets:
>>> ‘Hello {} world and our blue {}'.format(‘beautiful', ‘planet')'Hello beautiful world and our blue planet'
  1. The following example uses a numeric order (note the change of order and the repetition in the template):
>>> ‘{0} {2} {1} and our {2} {3}!'.format('Hello','World','Beautiful', 'Planet')'Hello Beautiful World and our Beautiful Planet!'
  1. The following example uses keywords: ...
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