Summary - String basics
- Python course
- Beginner
- Lesson 35/116
- 5 min
Combine f-string, join and format to write a business card.
Summary - String basics
In this group you learned f-strings, concatenation, str.format, raw strings and triple quotes.
- f-string:
f"{var}" - +: concatenation
- str.format:
"{}".format(v) - r: raw string
- """: multi-line string
Now two tasks combine these concepts.
This summary shows how string handling comes together in a real project.
This summary shows how string handling comes together in a real project.
This summary shows how string handling comes together in a real project.
This summary shows how string handling comes together in a real project.
This summary shows how string handling comes together in a real project.
Practice Print with f-string
Assign name = "Alex" and age = 25. Print print(f"{name} is {age}").
Starter code
# Use an f-stringSample solution
name = "Alex"
age = 25
print(f"{name} is {age}")Expected output
Alex is 25
Practice Multi-line and concatenation
Assign first = "Hello" and second = "World". Print print(first + " " + second).
Starter code
# Use concatenationSample solution
first = "Hello"
second = "World"
print(first + " " + second)Expected output
Hello World
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which is wrong?
- f"{}" embeds variables
- """ declares a number Correct answer
- r"" is a raw string
- + concatenates strings
Explanation: """ is for multi-line strings, not numbers.
2 Concatenation operator
print("a" + ____ + "b")
print("a" + "b" + "b")
Explanation: + is the concatenation operator.