CodeBlanks Logo Icon CodeBlanks

Summary - String basics

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

main.py
# Use an f-string

Sample solution

main.py
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

main.py
# Use concatenation

Sample solution

main.py
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

Question
print("a" + ____ + "b")
Answer
print("a" + "b" + "b")

Explanation: + is the concatenation operator.

All lessons in Beginner