What are strings?
Strings are text - any characters inside quotes. Python doesn’t care if you use single or double quotes, just be consistent.Creating strings
Three ways to make strings:Combining strings
Join strings together with+:
String length
Uselen() to count characters:
Converting to string
Turn other types into strings withstr():
Adjacent String Literals
Python automatically concatenates adjacent string literals into a single string.Example
Important
Spaces are not added automatically.String .format() Method
The .format() method replaces {placeholders} in a string with actual values.
This is useful for creating dynamic prompt templates.
Basic Prompt Example
Multiple Variables
A prompt can contain multiple placeholders:RAG-Style Prompt
A common RAG prompt contains both context and a question:Why This Matters in LangChain
LangChain’s prompt templates use the same{variable} style:
.format()is Python’s string formatting mechanism.ChatPromptTemplateprovides a similar placeholder-based mechanism specifically for building prompts.
Common mistakes
Mixing quotes
Mixing quotes
Can't add strings and numbers
Can't add strings and numbers
Forgetting quotes entirely
Forgetting quotes entirely
What’s next?
Let’s explore True/False values - essential for making decisions in your code!Booleans
True and False values