Skip to content

Latest commit

 

History

History
27 lines (27 loc) · 1.15 KB

Format_Function.md

File metadata and controls

27 lines (27 loc) · 1.15 KB

Format Function

The .format() method of the str type is an extremely convenient way to format text exactly the way you want it.
Here is the general form: 
template.format(p0, p1, ..., k0=v0, k1=v1, ...)
The arguments to the .format() method are of two types. The list starts with zero or more positional arguments pi, followed by zero or more keyword arguments of the form ki=vi, where each ki is a name with an associated value vi.

Example

1.Here we could see that if there are are no values in the curly brackets it directly maps according to the position. And if there are are position given in the curly brackets then it maps them according to the given index.

Code1

2.If you want to shift a no to right then you can include the no of spaces required after the colon

Code2

3.For printing a no its square and its cube we can use the formatting techniques.

Code3

We could see the difference when we use the formatting tools. The 1st one uses formatting functions.

Code4

4.We can use it for rounding of some values to given decimal points.