Your First Text Program in Python
Read a string and count its words.
Your First Text Program in Python is a free NLP Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the NLP Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Time to Write Code
Enough theory, let us write real Python. Your first NLP program will read a sentence and count its words. 🐍
Text Lives in Strings
In Python, a piece of text is a string, written inside quotes. It is the basic container for every word you process.
text = "NLP turns words into meaning"Print to See It
Use print to show a value on screen. It is the simplest way to check that your text loaded correctly.
text = "NLP turns words into meaning"
print(text)Splitting Into Words
The split method breaks a string at the spaces, handing you back a clean list of individual words.
words = text.split()
print(words)A List of Tokens
That result is a list, your very first set of tokens. Each item is one word, ready to be counted or examined.
Counting With len
Wrap the list in len to count its items. This single function tells you how many words the sentence holds.
count = len(words)
print(count)Putting It Together
A few lines do real NLP: store text, split it, and count the words. You just built a tiny word counter.
text = "NLP turns words into meaning"
words = text.split()
print(len(words))Try Your Own Sentence
Swap in any sentence you like and run it again. The same three lines work on a tweet, a review, or a poem.
Words vs Characters
Call len on the string itself, not the list, and you count characters instead, spaces included.
print(len(text))Why This Matters
Counting words feels small, but it is the foundation. Every advanced model still begins by splitting text into pieces.
You Did It
You wrote and understood a working NLP program. From here you only add steps, never start from scratch again. 🎉
Quick Check
You have a string in words after calling split. How do you count the words?
Recap
You stored text in a string, split it into a list, and counted with len: your first real NLP program in Python. 🏆
Frequently asked questions
Is the “Your First Text Program in Python” lesson free?
Yes — the full text of “Your First Text Program in Python” is free to read here on the web, and the NLP Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the NLP Academy course, upgrade to CoddyKit PRO.
What will I learn in “Your First Text Program in Python”?
Read a string and count its words. You practise NLP Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start NLP Academy?
No prior experience is required. NLP Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Your First Text Program in Python” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this NLP Academy lesson?
Yes. Every NLP Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- From Words to Meaning: The NLP Idea
- NLP You Use Every Day
- The NLP Pipeline at a Glance
- Your First Text Program in Python