文字列、文字、エンコーディング
テキストがバイトと Unicode として保存される仕組み
「文字列、文字、エンコーディング」はCoddyKit上の無料NLP Academyレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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. ✅
よくある質問
「文字列、文字、エンコーディング」レッスンは無料ですか?
はい。「文字列、文字、エンコーディング」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、NLP Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 NLP Academyコースには全4レッスンが含まれています。
「文字列、文字、エンコーディング」で何を学びますか?
テキストがバイトと Unicode として保存される仕組み ブラウザで直接実行するハンズオンコードでNLP Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
NLP Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのNLP Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。
「文字列、文字、エンコーディング」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このNLP Academyレッスンでコードを書いて実行できますか?
はい。すべてのNLP Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- 文字列、文字、エンコーディング
- テキストファイルを Python に読み込む
- 単語と文字を数える
- 初めての単語頻度表を作る