Bird
0
0

Given the code:

medium📝 component behavior Q4 of 15
LangChain - Prompt Templates
Given the code:
from langchain.prompts import PromptTemplate
prompt = PromptTemplate(template="Welcome, {user}!")
result = prompt.format(user="Alice")
print(result)

What will be printed?
AWelcome, {user}!
BWelcome, Alice!
CWelcome, user!
DError: missing variable
Step-by-Step Solution
Solution:
  1. Step 1: Understand the template and format call

    The template has a placeholder {user}. The format method replaces {user} with the value "Alice".
  2. Step 2: Predict the output of print(result)

    After formatting, the string becomes "Welcome, Alice!" which is printed.
  3. Final Answer:

    Welcome, Alice! -> Option B
  4. Quick Check:

    Formatted template output = Welcome, Alice! [OK]
Quick Trick: format() fills placeholders with given values [OK]
Common Mistakes:
  • Printing template without formatting
  • Confusing placeholder with literal text
  • Expecting error without missing variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LangChain Quizzes