0Pricing
NLP Academy · Lezione

Contare parole e caratteri

Misure di base di lunghezza e frequenza

Contare parole e caratteri è una lezione NLP Academy gratuita su CoddyKit. Questa è la lezione 3 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.

Measuring Text First

Before any fancy analysis, you measure text. Simple counts of characters and words already tell you a lot about a document. 📏

Count Characters With len

The len function returns how many characters a string holds, including spaces and punctuation.

text = "NLP is fun"
print(len(text))  # 10

Spaces Count Too

Remember that whitespace like spaces and newlines are real characters, so they are included in any character count.

Split Into Words

The split method breaks a string on whitespace and returns a list of words, your simplest path to word counting.

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

Count the Words

Apply len to the list from split and you get the word count of the whole document.

words = text.split()
print(len(words))  # number of words

Split Is Naive

Plain split treats hello! as one word because punctuation sticks to letters. Good enough to start, but not perfect.

Count Sentences Roughly

A quick sentence estimate is to count periods, question marks, and exclamation points. It is rough but instantly useful.

n = text.count(".") + text.count("?") + text.count("!")

Average Word Length

Divide total letters by word count to get average word length, a small signal about how dense the writing is.

avg = len(text.replace(" ", "")) / len(words)

Counting Specific Substrings

The count method tells you how many times a substring appears, handy for tallying a single target word.

print(text.lower().count("the"))

Unique Words With a Set

Put the word list into a set and its length is the number of unique words, a measure of vocabulary richness.

unique = set(words)
print(len(unique))

Why Counts Matter

These statistics drive real decisions: spam filters flag odd lengths, and readability tools lean on word counts.

Quick Check

Test your grasp of basic Python text counting.

Recap: Counting Text

You can now count characters with len, words with split, unique words with a set, and rough sentences by punctuation. 🔢

Domande Frequenti

La lezione «Contare parole e caratteri» è gratuita?

Sì — il testo completo di «Contare parole e caratteri» è 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 «Contare parole e caratteri»?

Misure di base di lunghezza e frequenza 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 3 di 4.

Quanto tempo richiede la lezione «Contare parole e caratteri»?

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

  1. Stringhe, caratteri e codifiche
  2. Leggere file di testo in Python
  3. Contare parole e caratteri
  4. Creare la prima tabella delle frequenze delle parole
← Torna a NLP Academy