Thinking Like a Programmer•Interactive notebook lesson•Free
String formatting
No account is required. Learn the material, try the examples, and mark it complete locally when you are ready to move on.
String formatting basics
Codepython
string1 = "This is a apple" # Creating a string
print(string1)Output
This is a apple
Codepython
fruit = "apple" # Assigning the string "apple" to the variable 'fruit'
string2 = "This is a {}".format(fruit)
# The '{}' is replaced with the value of 'fruit' using .format()
print(string2) # Output: This is a apple
Output
This is a apple
Code