Il primo programma di testo in Python
Leggere una stringa e contarne le parole
Il primo programma di testo in Python è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 4 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento NLP Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso NLP Academy include 4 lezioni in totale.
Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.
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. 🏆
Domande Frequenti
La lezione «Il primo programma di testo in Python» è gratuita?
Sì — il testo completo di «Il primo programma di testo in Python» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso NLP Academy, passa a CoddyKit PRO. Il corso NLP Academy include 4 lezioni in totale.
Cosa imparerò in «Il primo programma di testo in Python»?
Leggere una stringa e contarne le parole Eserciti NLP Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.
Ho bisogno di esperienza per iniziare NLP Academy?
Non è richiesta alcuna esperienza precedente. NLP Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 4 di 4.
Quanto tempo richiede la lezione «Il primo programma di testo in Python»?
La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.
Posso scrivere ed eseguire codice in questa lezione NLP Academy?
Sì. Ogni lezione NLP Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.
Tutte le lezioni di questo corso
- Dalle parole al significato: l'idea dell'NLP
- L'NLP che usa ogni giorno
- La pipeline NLP in sintesi
- Il primo programma di testo in Python