Another way to format strings is the string.format method.
This method indicates the places we want to change on a sting with curly braces.
For example, there is a variable named Linkedin below, and two sections are left blank with curly braces.
We pill place values in these sections wiht the string.format method. So how do we do it?
We write the variable we want to format. Then we call the format method by putting a period.
We write whatever we want to appear in the blank spaces in the method parenthesis.
For example, there are two print functions below. Formatting was done according to its values and the string expression we wanted to come as output.
Values in format brackets have idex numbers.
We can put these index numbers in curyl braces in the string so that the output is as we want.
For example, below, the values in the format brackets were mixed.
In order for the output to be as we want, we wrote the index numbers of the values in the parentheses in the curly brackets in the order we want.
As a result, we got the output in the order we wanted.
In the String.format method, the variable name can also be enclosed in the format brackets.
'Python' 카테고리의 다른 글
String Formatting With String.Format Method in Python (0) | 2024.10.16 |
---|---|
String Formatting With % Operator in Python (0) | 2024.10.15 |
String Formatting with Arithmetic Operations in Python (0) | 2024.10.11 |
Complex Indexing and Slicing Operations in Python (0) | 2024.10.10 |
Indexing and Slicing in Strings in Python (0) | 2024.10.02 |