(Part 5) The Python Language

The Python Language (Part 5)

Copyright ? 2021 by Robert M. Dondero, Ph.D.

Princeton University

1

Objectives

? We will cover:

? A subset of Python... ? That is appropriate for COS 333... ? Through example programs

2 Objectives Continued from Part 4 [see slide]

Agenda

? Prelim: character and string encodings ? Files ? The "with" statement ? Arrays ? Associative arrays ? Iterable classes ? Variadic functions/methods

3

Character Encodings

Examples:

Encoding

ASCII Latin-1 UCS-2 UCS-4 UTF-8 UTF-16

Fixed/Variable Width Fixed Fixed Fixed Fixed Variable Variable

Bytes

1 (7 bits) 1 2 4 1, 2, 3, or 4 2 or 4

4

Character Encodings

As you know, any modern computer deals with all data as bytes 1 byte = 8 bits

To deal with characters, any computer must use a character encoding A character encoding maps each character to the byte(s) which represent it

There are many character encodings

[see slide]

ASCII is a fixed-width encoding in which each character is mapped to 1 byte ...

Character Encodings

Character ASCII Latin-1 UCS-2 UCS-4 UTF-8 UTF-16

space

20

20

0020 00000020 20

0020

!

21

21

0021 00000021 21

0021

0

30

30

0030 00000030 30

0030

A

41

41

0041 00000041 41

0041

a

61

61

0061 00000061 61

0061

a with grave

Greek small pi

Double prime

Aegean number 2000

e0

00e0 000000e0 e0

00e0

03c0 000003c0 cf80

03c0

2033 00002033 e280b3 2033

00010123 f09084a3 d800dd23

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download