Bird
0
0

Which of the following is the correct syntax to use an f-string to insert variable name into a string?

easy📝 Syntax Q12 of 15
Python - Input and Output
Which of the following is the correct syntax to use an f-string to insert variable name into a string?
A"Hello, $name!"
Bf"Hello, {name}!"
Cf'Hello, $name!'
D"Hello, {name}!"
Step-by-Step Solution
Solution:
  1. Step 1: Identify f-string syntax

    An f-string starts with the letter f before the quotes and uses curly braces {} to insert variables.
  2. Step 2: Check each option

    f"Hello, {name}!" correctly uses f"Hello, {name}!". Options A and B lack the f prefix, and C uses incorrect syntax with $name.
  3. Final Answer:

    f"Hello, {name}!" -> Option B
  4. Quick Check:

    f-string = f"text {var}" [OK]
Quick Trick: f-string must start with f and use {variable} inside quotes [OK]
Common Mistakes:
MISTAKES
  • Omitting the f before the string
  • Using $ instead of curly braces
  • Using single quotes without f prefix

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes