Working with Strings
Strings are essential for AI applications — prompts, responses, and message formatting all use strings extensively.
String Creation
# Single or double quotes
message = "Hello, AI!"
message = 'Hello, AI!'
# Multi-line strings
prompt = """
You are a helpful assistant.
Respond concisely.
"""F-Strings (Formatted Strings)
The most powerful way to build prompts:
name = "Alice"
greeting = f"Hello, {name}!"Common String Methods
.strip()— Remove whitespace.lower()/.upper()— Change case.split()— Split into list.replace()— Replace text.startswith()/.endswith()— Check patterns