Chapter 2. Types and Variables
A good name is rather to be chosen than great riches.
Proverbs 22:1
Computer programs consist of commands (often shorthanded as code) and data. This chapter introduces the basics of how computers handle data, and how Python is a bit different from many programming languages.
A Computer
What’s in a typical computer?
- A central processing unit (CPU), or chip
-
The brains of the operation. Most computers now have multiple cores per CPU, and we’ll say more about this in Chapters 23 and 27.
- Random access memory (RAM)
-
The fast but limited storage area for data and programs.
- Cache memory
-
Like RAM, but smaller and faster.
- A disk
-
Stores much more data than RAM does but is thousands of times slower.
- Local input devices
-
Keyboards, touchscreens, mice, cameras, and microphones.
- Local output devices
-
Displays and printers.
- A network
-
Communicates with other computers, either through cables or the air.
The CPU, RAM, and cache are volatile: they work only while electricity is flowing through them. The disk is nonvolatile, retaining its data even when the whole computer is turned off. A continual struggle occurs between RAM/cache (fast but limited) and disk (slow but roomier) to balance a computer’s performance.
Computer programs and data are stored on the disk and transferred to RAM when the CPU needs to access them. The CPU fetches (reads) from RAM and stores (writes) back.
In this book, I’ll liken RAM to a series of bookshelves, where each rack is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access