เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง
ขั้นตอนแรกในการทำให้ข้อมูลเป็นมาตรฐาน
เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Your First Two Steps
The simplest normalization is folding case and trimming spaces. Master these two and you already remove most of the noise that splits your word counts. ✨
Lowercasing in One Call
Python strings carry a built-in lower method. It returns a fresh copy with every letter folded to lowercase, leaving the original untouched.
text = 'The QUICK Fox'
print(text.lower())Now They Match
Once both sides are lowercased, the case difference vanishes and the comparison finally returns True. That is the whole point of case folding.
print('Paris'.lower() == 'paris')Trimming the Edges
The strip method removes whitespace from both ends of a string. Leading and trailing spaces, tabs, and newlines all disappear in one call.
messy = ' hello world '
print(messy.strip())One-Sided Trims
Sometimes you only want one edge cleaned. Use lstrip for the left side and rstrip for the right when you need that control.
print(' hi'.lstrip())
print('hi '.rstrip())Spaces in the Middle
Strip only touches the ends. To squash repeated spaces inside text, split on whitespace and rejoin, which collapses every gap to a single space.
text = 'too many spaces'
print(' '.join(text.split()))Why Split Then Join
Calling split with no argument breaks on any run of whitespace and drops the empties. Rejoining with one space gives you clean, even spacing.
Chain Them Together
Because each method returns a string, you can chain them. Here you lowercase and strip a value in a single readable pipeline.
raw = ' CoddyKit '
print(raw.lower().strip())Strings Are Immutable
These methods never change the original; they hand back a new string. Always capture the result in a variable or you lose the cleaned value.
s = 'HELLO'
s.lower()
print(s)Normalize a Whole List
Apply your two steps to every token at once with a comprehension. Now each word is lowercase and trimmed, ready for counting.
words = [' Cat ', 'DOG', 'Cat']
print([w.lower().strip() for w in words])Counts Finally Agree
After folding case, the three messy entries for cat collapse into one matching token, so your frequency table tells the truth. 📊
Quick Check
Let's confirm how to clean spacing.
Recap
You learned to fold case with lower and trim edges with strip, then collapse inner gaps with split and join. Your tokens now match cleanly. Nice work! 🎉
คำถามที่พบบ่อย
บทเรียน “เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง”
ขั้นตอนแรกในการทำให้ข้อมูลเป็นมาตรฐาน คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- เหตุใดตัวพิมพ์และการเว้นวรรคจึงสำคัญ
- เปลี่ยนเป็นตัวพิมพ์เล็กและตัดช่องว่าง
- การตัดคำ: ตัดให้เหลือรากศัพท์
- การทำเลมมาไทเซชัน: รูปพื้นฐานที่ฉลาดขึ้น