สตริง อักขระ และการเข้ารหัส
วิธีจัดเก็บข้อความเป็นไบต์และ Unicode
สตริง อักขระ และการเข้ารหัส เป็นบทเรียน NLP Academy ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน NLP Academy และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Text Is Made of Characters
Every piece of text you process is a string: an ordered run of characters like letters, digits, spaces, and symbols. 🔤
Strings in Python
In Python a string is wrapped in quotes. You can store a whole sentence in a single variable and work with it as one value.
text = "NLP turns text into insight"
print(type(text)) # <class 'str'>Each Character Has a Position
A string is indexed, so each character sits at a numbered position starting from zero. That lets you reach any single letter.
word = "data"
print(word[0]) # d
print(word[3]) # aComputers Store Numbers
A computer cannot store the letter A directly. It stores a number, and an encoding is the agreed map between characters and those numbers.
ASCII Came First
ASCII mapped 128 basic English characters to numbers. It worked for plain English but had no room for accents or other alphabets.
Unicode Covers Everything
Unicode gives every character a unique code point, from English letters to Chinese script and emoji. Modern Python strings are Unicode.
Code Points in Python
The ord function shows a character's Unicode number, and chr turns a number back into its character.
print(ord('A')) # 65
print(chr(233)) # éEncoding Turns Text Into Bytes
To save or send text, Python turns it into bytes using a scheme like UTF-8. Bytes are what files and networks actually carry.
data = "café".encode("utf-8")
print(data) # b'caf\xc3\xa9'UTF-8 Is the Default Choice
UTF-8 stores common characters in one byte and rarer ones in more. It is compact, universal, and the standard for almost all text today.
Decoding Bytes Back to Text
Reading raw bytes means decoding them with the same scheme used to encode. The wrong scheme produces garbled or broken characters.
raw = b'caf\xc3\xa9'
print(raw.decode("utf-8")) # caféEncoding Mistakes Cause Mojibake
Decoding with the wrong encoding gives mojibake, that jumble of odd symbols. Always know and match your encoding to avoid it.
Quick Check
Let us check the difference between two key text standards.
Recap: Text as Encoded Strings
You saw that text is a string of characters, mapped to numbers by Unicode and stored as UTF-8 bytes. Match encodings and your text stays clean. ✅
คำถามที่พบบ่อย
บทเรียน “สตริง อักขระ และการเข้ารหัส” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “สตริง อักขระ และการเข้ารหัส” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส NLP Academy ให้อัปเกรดเป็น CoddyKit PRO คอร์ส NLP Academy มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “สตริง อักขระ และการเข้ารหัส”
วิธีจัดเก็บข้อความเป็นไบต์และ Unicode คุณปฏิบัติ NLP Academy ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน NLP Academy หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน NLP Academy บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “สตริง อักขระ และการเข้ารหัส” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน NLP Academy นี้ได้ไหม
ได้ บทเรียน NLP Academy ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- สตริง อักขระ และการเข้ารหัส
- อ่านไฟล์ข้อความเข้าสู่ Python
- การนับคำและอักขระ
- สร้างตารางความถี่คำแรกของคุณ