Python
2: Escape Sequence
3: Comments
4: Escape Sequence as Normal Text
5: Print Emoji
6: Python as Calculator
7: Strings Concatenation
8: Input
9: int function
10: Variables
11: String Formatting
12: String Indexing
13: String Slicing
14: Step Argument
15: Some useful function and methods
16: Strip Method
17: Find and Replace method
18: Center method
19: If Statement
20: If else statement
21: Nested if-else Statement
22: if-elif-else statement
23: while loop
23.1: Example 1 while loop
23.2: Example 2 while loop
23.3: Example 3 while loop
24: Infinite loop
25: for loop
25.1: Example 1 for loop
26: break and continue statement
27: for loop with string
Chapter 11: String Formatting
In Python, there are three main methods for string formatting.
1. In the first type of formatting, we concatenate strings using the + symbol, as shown in the example below.
language = "Python"
website = "Free Learning"
print("I'm learning " + language + " language from " + website + " website.")
Output: I'm learning Python language from Free Learning website.
2. In the second type, we use curly braces {} inside double quotes and the .format() method for formatting, as shown in the code. This formatting is available for python version 3 and higher.
language = "Python"
website = "Free Learning"
print("I'm learning {} language from {} website.".format(language,website))
Output: I'm learning Python language from Free Learning website.
3. In the third type, we use curly braces {} inside double quotes with an f prefix before the quotes for f-string formatting, as shown in the code. This formatting is available for python version 3.6 and higher.
language = "Python"
website = "Free Learning"
print(f"I'm learning {language} language from {website} website.")
Output: I'm learning Python language from Free Learning website.
You can use any of the string formatting, you like.