0Pricing
NLP Academy · บทเรียน

การนับคำและอักขระ

การวัดความยาวและความถี่เบื้องต้น

การนับคำและอักขระ เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

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. 🔢

คำถามที่พบบ่อย

บทเรียน “การนับคำและอักขระ” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การนับคำและอักขระ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การนับคำและอักขระ”

การวัดความยาวและความถี่เบื้องต้น คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “การนับคำและอักขระ” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม

ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. สตริง อักขระ และการเข้ารหัส
  2. อ่านไฟล์ข้อความเข้าสู่ Python
  3. การนับคำและอักขระ
  4. สร้างตารางความถี่คำแรกของคุณ
← กลับไปที่ NLP Academy