March 2020
Beginner to intermediate
352 pages
8h 40m
English
We can use the format() method to format a string in Python. This method is very flexible and powerful when displaying output in any particular format. The format() method holds curly braces {} as placeholders that can be replaced by any particular arguments according to a specific order. Have a look at these next examples.
Let's first see an example for a default order:
# Default order String1 = "{} {} {}".format('Exploratory ', 'Data ', 'Analysis') print("Print String in default order: ") print(String1)
The output of the preceding code is as follows:
Print String in default order:Exploratory Data Analysis
In addition to this default order, we can use positional formatting. For example, you have a string such as
Read now
Unlock full access