August 2025
Beginner to intermediate
248 pages
6h 10m
English
|
9 |
While they are not a compound data type, strings come with a broad range of methods and management options as we will explore in this chapter.
In Python, you will often need to insert a variable value into your string for printing a message as shown in Example 1.
Example 1
name = "Oliver"
print("Hi " + name)
Out: Hi Oliver
The name variable is used to insert a pre-defined name into the print message. However, we can also customize the input using the .format method. Rather than creating a fixed variable, we can use curly brackets {} as a placeholder for the variable value to be inputted. The input value can then be added or updated inside the dot format parentheses.
Example 2
Read now
Unlock full access