0% found this document useful (0 votes)
2 views4 pages

Understanding Python Character Sets

Uploaded by

Chithra Robinson
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Understanding Python Character Sets

Uploaded by

Chithra Robinson
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

The image contains text from a programming book or guide, specifically about Python's

handling of characters and the structure of Python programs. Here's an explanation in simpler
terms:

Python Character Set

 ASCII and Unicode: Python originally used ASCII (a basic character set), but
modern Python uses Unicode, which supports characters from many languages and
symbols (including emojis).
 This is important because today's programs often need to show messages in various
languages or handle different characters.
 Python strings use Unicode, so Python can represent and manipulate characters from
many different writing systems.

Unicode

 Unicode is a standard (see: [Link]) that assigns a unique number (code point) to
every character used in human languages.
 This standard is constantly updated to include new languages and symbols.
 Example: 'A', 'B', 'C' are different characters; so are '1' (digit one) and 'Ⅰ'
(Roman numeral one). They may look similar but have different meanings and
different Unicode values.
 Each character has a code point — an integer. Unicode ranges from 0 to 0x10FFFF,
which is over 1 million possible values (though only about 110,000 are currently
used).

Lexical Structure

 This section talks about the rules (or grammar) for writing Python programs.
 It’s about:
o How variables and functions are named,
o How code is written and formatted,
o What symbols and punctuation are allowed,
o How comments are used.
 Python programs are made up of sequences of lines, tokens, and statements.
 Python is very strict about indentation (the use of spaces/tabs at the beginning of
lines), so it's important to pay attention to this — especially if you're used to a
different language that’s more flexible.

Let me know if you'd like a summary, quiz, or explanation of any part in more detail!

You said:
ascii code
ChatGPT said:

What is ASCII Code?

ASCII stands for American Standard Code for Information Interchange. It is a


character encoding standard used in computers and electronic devices to represent text.

Key Points About ASCII:

 ASCII uses 7 bits to represent each character.


 It can represent 128 characters:
o 0–31: Control characters (like newline, tab, etc.)
o 32–126: Printable characters (letters, digits, symbols, punctuation)
o 127: DEL (delete)

Examples of ASCII Codes:

Character ASCII Code (Decimal) ASCII Code (Binary)


A 65 01000001
a 97 01100001
0 48 00110000
Space 32 00100000
@ 64 01000000
! 33 00100001

Why ASCII is Important:

 It's the foundation of most text encoding systems.


 Unicode, used in Python today, includes ASCII as its subset (i.e., the first 128
characters in Unicode are exactly the ASCII characters).

Python Example:

You can get the ASCII code of a character using ord() and convert back using chr():

python
CopyEdit
print(ord('A')) # Output: 65
print(chr(65)) # Output: 'A'

Let me know if you want the full ASCII table or a small Python program to display it!
You said:

python character set


ChatGPT said:

Python Character Set Explained

In Python, a character set refers to the collection of characters that the language can
recognize and work with. Python supports a wide range of characters because it uses
Unicode, which is much more powerful than the older ASCII system.

🔤 1. ASCII Character Set (Basic)

 ASCII stands for American Standard Code for Information Interchange.


 Contains 128 characters, including:
o Uppercase and lowercase English letters (A-Z, a-z)
o Digits (0-9)
o Symbols (!, @, #, etc.)
o Control characters (newline, tab, etc.)

📌 Limitation: ASCII only supports English characters.

🌍 2. Unicode Character Set (Used in Python)

 Unicode is a universal character set that supports characters from virtually every
language, including:
o English, Hindi, Chinese, Arabic, Tamil, etc.
o Special characters like emojis (😊), math symbols (∑, √), currency (₹, ¥), etc.
 Python's strings (str type) are Unicode by default.

💡 Example:

python
CopyEdit
print("Hello, 😊")
print(ord('😊')) # Outputs: 128522
print(chr(128522)) # Outputs: 😊

📚 Why Python Uses Unicode

 To support international applications.


 To handle multilingual data, emoji, symbols, and custom characters.
 Makes Python programs portable and global-ready.
✅ Summary

Feature ASCII Unicode


Characters 128 Over 1 million
Supports English only Almost all world languages
Used in Python Originally (old versions) Yes (default in Python 3)

You might also like