The Language of Intelligence

Part of the free Generative AI course on LogicWiz — module: Awakening the Machine.

Episode 2: The Language of Intelligence

"AI doesn't think in numbers. It thinks in text."


Nova Thinks in Words

In the last episode, you taught your machine to remember values and do math. But here's a secret about the AI world:

Almost everything is text.

  • Every prompt you send to Nova? A string.
  • Every response Nova generates? A string.
  • Every article Nova will search through? Strings.
  • Every conversation Nova will remember? Strings.

Strings are an ordered, immutable sequence of characters. Master them, and you'll control the very medium Nova thinks in.

If variables are Nova's memory, strings are her language. This episode teaches you to speak it fluently.


Creating Strings

Strings can be written with single quotes, double quotes, or triple quotes:

single_quoted = 'Hello, World!'
double_quoted = "Hello, World!"

Escape Characters

If your string contains an apostrophe, either use double quotes on the outside or escape with a backslash:

double_without_escape = "It's a beautiful day."
single_with_escape = 'It\'s a beautiful day.'

Triple Quotes for Multi-Line Strings

Triple single quotes (''') or triple double quotes (""") create multi-line strings. You'll default to these when writing prompts for LLMs:

multi_line = """
This is a multi-line string.
It can span multiple lines without needing escape characters.
"""

F-Strings with Triple Quotes (The Nova Pattern)

This is how you'll build Nova's prompts — combine f-strings with triple quotes for readable, multi-line instructions:

text = "Some long article content..."
prompt = f"""Summarize the following text into a single sentence:
{text}
"""

This is exactly how Nova will talk to AI models — instructions plus context, formatted as a single string.

{{cell:l2-try-create}}


Dissecting Text: Indexing

When Nova processes a response from an AI model, she might need to inspect specific characters. Strings are sequences, and you can access any character by its position:

text = "Python"
print(text[0])   # P
print(text[1])   # y
print(text[-1])  # n  (negative index starts from the end)
print(text[-2])  # o

{{cell:l2-try-index}}


Length with len()

text = "GenAI"
print(len(text))   # 5

{{cell:l2-try-len}}


Extracting Information: Slicing

Nova will often need to extract parts of text — a headline from an article, or the first sentence of a response. Slicing extracts a substring using [start:end].

  • start is inclusive
  • end is exclusive
text = "Hello World"
print(text[0:5])   # Hello
print(text[6:11])  # World
print(text[:5])    # Hello
print(text[6:])    # World

{{cell:l2-try-slice}}


Building Prompts Piece by Piece: Concatenation

Sometimes you'll build Nova's prompts from multiple pieces. The + operator acts like "glue" for strings:

str1 = "Hello"
str3 = "World"
concatenated = str1 + " " + str3
print(concatenated)   # Hello World

String Formatting Methods

F-Strings (Preferred)

name = "Alice"
age = 30
print(f"My name is {name} and I am {age} years old.")

.format() Method

An older but still common approach. Order of variables matters:

formatted = "My name is {} and I am {} years old.".format(name, age)
print(formatted)

F-strings are preferred because you insert variable names directly — no need to match positions.


Nova's Text Toolkit: Common String Methods

.lower() and .upper()

text = "Hello, Python!"
print(text.lower())   # hello, python!
print(text.upper())   # HELLO, PYTHON!

.capitalize() and .title()

text = "hello world"
print(text.capitalize())   # Hello world  (first char only)
print(text.title())        # Hello World  (each word)

.strip(), .lstrip(), .rstrip()

text = "   hello   "
print(text.strip())    # "hello"     removes both sides
print(text.lstrip())   # "hello   "  removes leading only
print(text.rstrip())   # "   hello"  removes trailing only

.replace(old, new)

text = "Hello, Python!"
print(text.replace("Python", "World"))   # Hello, World!

{{cell:l2-try-methods}}


Breaking and Rebuilding Text: .split() and .join()

.split()

When Nova receives a long response, she might need to break it into individual words or sentences. .split() splits a string into a list of substrings. Without arguments, it splits by any whitespace and intelligently handles multiple spaces:

sentence = "Today   is a great   day"
print(sentence.split())
# ['Today', 'is', 'a', 'great', 'day']  extra spaces ignored!

With a custom delimiter:

text = "one,two,three"
print(text.split(","))   # ['one', 'two', 'three']

.join()

The reverse of split() — takes a list and glues items with a delimiter:

words = ['Today', 'is', 'great']
print(" ".join(words))    # Today is great
print("--".join(words))   # Today--is--great

{{cell:l2-try-split-join}}


Mission 2: Clean Nova's Input Pipeline

Nova can't work with messy text. You'll write normalize_prompt(text) — a function that cleans user input before it becomes a prompt:

  • Lowercase
  • Strip whitespace
  • Replace spaces with single spaces (extra credit)
  • Convert multiple spaces / newlines into clean formatting

Complete this mission to solidify your Code Initiate title.

Next up: Nova can speak and understand text. But real intelligence needs structure — lists of messages, dictionaries of settings, organized collections of data. In the next episode, you'll learn to organize information the way AI systems actually store it...