فهرست مطالب :
Cover
Title Page
Copyright Page
Dedication
Brief Content
Content
VIDEONOTES
PREFACE
PREFACE TO THE SECOND EDITION
1.0.1 Data Manipulation
1.0.2 Problem Solving and Case Studies
1.0.3 Code Examples
1.0.4 Interactive Sessions
1.0.5 Exercises and Programming Projects
1.0.6 Self-Test Exercises
1.0.7 Programming Tips
PART 1 THINKING ABOUT COMPUTING
Chapter 0 The Study of Computer Science
0.1 Why Computer Science?
0.1.1 Importance of Computer Science
0.1.2 Computer Science Around You
0.1.3 Computer “Science”
0.1.4 Computer Science Through Computer Programming
0.2 The Difficulty and Promise of Programming
0.2.1 Difficulty 1: Two Things at Once
0.2.2 Difficulty 2: What Is a Good Program?
0.2.3 The Promise of a Computer Program
0.3 Choosing a Computer Language
0.3.1 Different Computer Languages
0.3.2 Why Python?
0.3.3 Is Python the Best Language?
0.4 What Is Computation?
0.5 What Is a Computer?
0.5.1 Computation in Nature
0.5.2 The Human Computer
0.6 The Modern, Electronic Computer
0.6.1 It’s the Switch!
0.6.2 The Transistor
0.7 A High-Level Look at a Modern Computer
0.8 Representing Data
0.8.1 Binary Data
0.8.2 Working with Binary
0.8.3 Limits
0.8.4 Representing Letters
0.8.5 Representing Other Data
0.8.6 What Does a Number Represent?
0.8.7 How to Talk About Quantities of Data
0.8.8 HowMuch Data Is That?
0.9 Overview of Coming Chapters
PART 2 STARTING TO PROGRAM
Chapter 1 Beginnings
1.1 Practice, Practice, Practice
1.2 QuickStart, the Circumference Program
1.2.1 Examining the Code
1.3 An Interactive Session
1.4 Parts of a Program
1.4.1 Modules
1.4.2 Statements and Expressions
1.4.3 Whitespace
1.4.4 Comments
1.4.5 Special Python Elements: Tokens
1.4.6 Naming Objects
1.4.7 Recommendations on Naming
1.5 Variables
1.5.1 Variable Creation and Assignment
1.6 Objects and Types
1.6.1 Numbers
1.6.2 Other Built-In Types
1.6.3 Object Types: Not Variable Types
1.6.4 Constructing New Values
1.7 Operators
1.7.1 Integer Operators
1.7.2 Floating-Point Operators
1.7.3 Mixed Operations
1.7.4 Order of Operations and Parentheses
1.7.5 Augmented Assignment Operators: A Shortcut!
1.8 Your First Module, Math
1.9 Developing an Algorithm
1.9.1 New Rule—Testing
1.10 Visual Vignette: Turtle Graphics
1.11 What’s Wrong with My Code?
Chapter 2 Control
2.1 QuickStart Control
2.1.1 Selection
2.1.2 Booleans for Decisions
2.1.3 The if Statement
2.1.4 Example: What Lead Is Safe in Basketball?
2.1.5 Repetition
2.1.6 Example: Finding Perfect Numbers
2.1.7 Example: Classifying Numbers
2.2 In-Depth Control
2.2.1 True and False: Booleans
2.2.2 Boolean Variables
2.2.3 Relational Operators
2.2.4 Boolean Operators
2.2.5 Precedence
2.2.6 Boolean Operators Example
2.2.7 Another Word on Assignments
2.2.8 The Selection Statement for Decisions
2.2.9 More on Python Decision Statements
2.2.10 Repetition: the while Statement
2.2.11 Sentinel Loop
2.2.12 Summary of Repetition
2.2.13 More on the for Statement
2.2.14 Nesting
2.2.15 Hailstone Sequence Example
2.3 Visual Vignette: Plotting Data with Pylab
2.3.1 First Plot and Using a List
2.3.2 More Interesting Plot: A Sine Wave
2.4 Computer Science Perspectives: Minimal Universal Computing
2.4.1 Minimal Universal Computing
2.5 What’s Wrong with My Code?
Chapter 3 Algorithms and Program Development
3.1 What Is an Algorithm?
3.1.1 Example Algorithms
3.2 Algorithm Features
3.2.1 Algorithm versus Program
3.2.2 Qualities of an Algorithm
3.2.3 Can We Really Do All That?
3.3 What Is a Program?
3.3.1 Readability
3.3.2 Robust
3.3.3 Correctness
3.4 Strategies for Program Design
3.4.1 Engage and Commit
3.4.2 Understand, Then Visualize
3.4.3 Think Before You Program
3.4.4 Experiment
3.4.5 Simplify
3.4.6 Stop and Think
3.4.7 Relax: Give Yourself a Break
3.5 A Simple Example
3.5.1 Build the Skeleton
3.5.2 Output
3.5.3 Input
3.5.4 Doing the Calculation
PART 3 DATA STRUCTURES AND FUNCTIONS
Chapter 4 Working with Strings
4.1 The String Type
4.1.1 The Triple-Quote String
4.1.2 Nonprinting Characters
4.1.3 String Representation
4.1.4 Strings as a Sequence
4.1.5 More Indexing and Slicing
4.1.6 Strings Are Iterable
4.2 String Operations
4.2.1 Concatenation (+) and Repetition (*)
4.2.2 Determining When + Indicates Addition or Concatenation?
4.2.3 Comparison Operators
4.2.4 The in Operator
4.2.5 String Collections Are Immutable
4.3 A Preview of Functions and Methods
4.3.1 A String Method
4.3.2 Determining Method Names and Method Arguments
4.3.3 String Methods
4.3.4 String Functions
4.4 Formatted Output for Strings
4.4.1 Descriptor Codes
4.4.2 Width and Alignment Descriptors
4.4.3 Floating-Point Precision Descriptor
4.5 Control and Strings
4.6 Working with Strings
4.6.1 Example: Reordering a Person’s Name
4.6.2 Palindromes
4.7 More String Formatting
4.8 Unicode
4.9 A GUI to Check a Palindrome
4.10 What’s Wrong with My Code?
Chapter 5 Functions—Quick Start
5.1 What Is a Function?
5.1.1 Why Have Functions?
5.2 Python Functions
5.3 Flow of Control with Functions
5.3.1 Function Flow in Detail
5.3.2 Parameter Passing
5.3.3 Another Function Example
5.3.4 Function Example: Area of a Triangle
5.3.5 Functions Calling Functions
5.3.6 When to Use a Function
5.3.7 What If There Is No Return Statement?
5.3.8 What If There Are Multiple Return Statements?
5.4 Visual Vignette: Turtle Flag
5.5 What’s Wrong with My Code?
Chapter 6 Files and Exceptions I
6.1 What Is a File?
6.2 Accessing Files: Reading Text Files
6.2.1 What’s Really Happening?
6.3 Accessing Files: Writing Text Files
6.4 Reading and Writing Text Files in a Program
6.5 File Creation and Overwriting
6.5.1 Files and Functions Example: Word Puzzle
6.6 First Cut, Handling Errors
6.6.1 Error Names
6.6.2 The try-except Construct
6.6.3 try-except Flow of Control
6.6.4 Exception Example
6.7 Example: Counting Poker Hands
6.7.1 Program to Count Poker Hands
6.8 GUI to Count Poker Hands
6.8.1 Count Hands Function
6.8.2 The Rest of the GUI Code
6.9 Error Check Float Input
6.10 What’s Wrong with My Code?
Chapter 7 Lists and Tuples
7.1 What Is a List?
7.2 What You Already Know How To Do With Lists
7.2.1 Indexing and Slicing
7.2.2 Operators
7.2.3 Functions
7.2.4 List Iteration
7.3 Lists Are Different than Strings
7.3.1 Lists Are Mutable
7.3.2 List Methods
7.4 Old and New Friends: Split and Other Functions and Methods
7.4.1 Split and Multiple Assignment
7.4.2 List to String and Back Again, Using join
7.4.3 The Sorted Function
7.5 Working with Some Examples
7.5.1 Anagrams
7.5.2 Example: File Analysis
7.6 Mutable Objects and References
7.6.1 Shallow versus Deep Copy
7.6.2 Mutable versus Immutable
7.7 Tuples
7.7.1 Tuples from Lists
7.7.2 Why Tuples?
7.8 Lists: The Data Structure
7.8.1 Example Data Structure
7.8.2 Other Example Data Structures
7.9 Algorithm Example: U.S. EPA Automobile Mileage Data
7.9.1 CSV Module
7.10 Visual Vignette: Plotting EPA Data
7.11 List Comprehension
7.11.1 Comprehensions, Expressions, and the Ternary Operator
7.12 Visual Vignette: More Plotting
7.12.1 Pylab Arrays
7.12.2 Plotting Trigonometric Functions
7.13 GUI to Find Anagrams
7.13.1 Function Model
7.13.2 Controller
7.14 What’s Wrong with My Code?
Chapter 8 More on Functions
8.1 Scope
8.1.1 Arguments, Parameters, and Namespaces
8.1.2 Passing Mutable Objects
8.1.3 Returning a Complex Object
8.1.4 Refactoring evens
8.2 Default Values and Parameters as Keywords
8.2.1 Example: Default Values and Parameter Keywords
8.3 Functions as Objects
8.3.1 Function Annotations
8.3.2 Docstrings
8.4 Example: Determining a Final Grade
8.4.1 The Data
8.4.2 The Design
8.4.3 Function: weighted_grade
8.4.4 Function: parse_line
8.4.5 Function: main
8.4.6 Example Use
8.5 Pass “by Value” or “by Reference”
8.6 What’s Wrong with My Code?
Chapter 9 Dictionaries and Sets
9.1 Dictionaries
9.1.1 Dictionary Example
9.1.2 Python Dictionaries
9.1.3 Dictionary Indexing and Assignment
9.1.4 Operators
9.1.5 Ordered Dictionaries
9.2 Word Count Example
9.2.1 Count Words in a String
9.2.2 Word Frequency for Gettysburg Address
9.2.3 Output and Comments
9.3 Periodic Table Example
9.3.1 Working with CSV Files
9.3.2 Algorithm Overview
9.3.3 Functions for Divide and Conquer
9.4 Sets
9.4.1 History
9.4.2 What’s in a Set?
9.4.3 Python Sets
9.4.4 Methods, Operators, and Functions for Python Sets
9.4.5 Set Methods
9.5 Set Applications
9.5.1 Relationship between Words of Different
9.5.2 Output and Comments
9.6 Scope: The Full Story
9.6.1 Namespaces and Scope
9.6.2 Search Rule for Scope
9.6.3 Local
9.6.4 Global
9.6.5 Built-Ins
9.6.6 Enclosed
9.7 Using zip to Create Dictionaries
9.8 Dictionary and Set Comprehensions
9.9 Visual Vignette: Bar Graph of Word Frequency
9.9.1 Getting the Data Right
9.9.2 Labels and the xticks Command
9.9.3 Plotting
9.10 GUI to Compare Files
9.10.1 Controller and View
9.10.2 Function Model
9.11 What’s Wrong with My Code?
Chapter 10 More Program Development
10.1 Introduction
10.2 Divide and Conquer
10.2.1 Top-Down Refinement
10.3 The Breast Cancer Classifier
10.3.1 The Problem
10.3.2 The Approach: Classification
10.3.3 Training and Testing the Classifier
10.3.4 Building the Classifier
10.4 Designing the Classifier Algorithm
10.4.1 Divided, now Conquer
10.4.2 Data Structures
10.4.3 File Format
10.4.4 The make_training_set Function
10.4.5 The make_test_set Function
10.4.6 The train_classifier Function
10.4.7 train_classifier, Round 2
10.4.8 Testing the Classifier on New Data
10.4.9 The report_results Function
10.5 Running the Classifier on Full Data
10.5.1 Training versus Testing
10.6 Other Interesting Problems
10.6.1 Tag Clouds
10.6.2 S&P 500 Predictions
10.6.3 Predicting Religion with Flags
10.7 GUI to Plot the Stock Market
10.7.1 Function Model
10.7.2 Controller and View
PART 4 CLASSES, MAKING YOUR OWN DATA STRUCTURES AND ALGORITHMS
Chapter 11 Introduction to Classes
11.1 QuickStart: Simple Student Class
11.2 Object-Oriented Programming
11.2.1 Python Is Object-Oriented!
11.2.2 Characteristics of OOP
11.3 Working with OOP
11.3.1 Class and Instance
11.4 Working with Classes and Instances
11.4.1 Built-In Class and Instance
11.4.2 Our First Class
11.4.3 Changing Attributes
11.4.4 The Special Relationship Between an Instance and Class: instance-of
11.5 Object Methods
11.5.1 Using Object Methods
11.5.2 Writing Methods
11.5.3 The Special Argument self
11.5.4 Methods Are the Interface to a Class Instance
11.6 Fitting into the Python Class Model
11.6.1 Making Programmer-Defined Classes
11.6.2 A Student Class
11.6.3 Python Standard Methods
11.6.4 Now There Are Three: Class Designer, Programmer, and User
11.7 Example: Point Class
11.7.1 Construction
11.7.2 Distance
11.7.3 Summing Two Points
11.7.4 Improving the Point Class
11.8 Python and OOP
11.8.1 Encapsulation
11.8.2 Inheritance
11.8.3 Polymorphism
11.9 Python and Other OOP Languages
11.9.1 Public versus Private
11.9.2 Indicating Privacy Using Double Underscores (__)
11.9.3 Python’s Philosophy
11.9.4 Modifying an Instance
11.10 What’s Wrong with My Code?
Chapter 12 More on Classes
12.1 More About Class Properties
12.1.1 Rational Number (Fraction) Class Example
12.2 How Does Python Know?
12.2.1 Classes, Types, and Introspection
12.2.2 Remember Operator Overloading
12.3 Creating Your Own Operator Overloading
12.3.1 Mapping Operators to Special Methods
12.4 Building the Rational Number Class
12.4.1 Making the Class
12.4.2 Review Fraction Addition
12.4.3 Back to Adding Fractions
12.4.4 Equality and Reducing Rationals
12.4.5 Divide and Conquer at Work
12.5 What Doesn’t Work (Yet)
12.5.1 Introspection
12.5.2 Repairing int + Rational Errors
12.6 Inheritance
12.6.1 The “Find the Attribute” Game
12.6.2 Using Inheritance
12.6.3 Example: The Standard Model
12.7 What’s Wrong with My Code?
Chapter 13 Program Development with Classes
13.1 Predator–Prey Problem
13.1.1 The Rules
13.1.2 Simulation Using Object-Oriented Programming
13.2 Classes
13.2.1 Island Class
13.2.2 Predator and Prey, Kinds of Animals
13.2.3 Predator and Prey Classes
13.2.4 Object Diagram
13.2.5 Filling the Island
13.3 Adding Behavior
13.3.1 Refinement: Add Movement
13.3.2 Refinement: Time Simulation Loop
13.4 Refinement: Eating, Breeding, and Keeping Time
13.4.1 Improved Time Loop
13.4.2 Breeding
13.4.3 Eating
13.4.4 The Tick of the Clock
13.5 Refinement: How Many Times to Move?
13.6 Visual Vignette: Graphing Population Size
PART 5 BEING A BETTER PROGRAMMER
Chapter 14 Files and Exceptions II
14.1 More Details on Files
14.1.1 Other File Access Methods, Reading
14.1.2 Other File Access Methods, Writing
14.1.3 Universal New Line Format
14.1.4 Moving Around in a File
14.1.5 Closing a File
14.1.6 The with Statement
14.1.7 Text File Encodings
14.2 CSV Files
14.2.1 CSV Module
14.2.2 CSV Reader
14.2.3 CSV Writer
14.2.4 Example: Update Some Grades
14.3 Module: os
14.3.1 Directory (Folder) Structure
14.3.2 os Module Functions
14.3.3 os Module Example
14.4 More on Exceptions
14.4.1 Basic Exception Handling
14.4.2 A Simple Example
14.4.3 Events
14.4.4 A Philosophy Concerning Exceptions
14.5 Exception: else and finally
14.5.1 finally and with
14.5.2 Example: Refactoring the Reprompting of a File Name
14.6 More on Exceptions
14.6.1 Raise
14.6.2 Create Your Own
14.7 Example: Password Manager
Chapter 15 Recursion: Another Control Mechanism
15.1 What Is Recursion?
15.2 Mathematics and Rabbits
15.3 Let’s Write Our Own: Reversing a String
15.4 How Does Recursion Actually Work?
15.4.1 Stack Data Structure
15.4.2 Stacks and Function Calls
15.4.3 A Better Fibonacci
15.5 Recursion in Figures
15.5.1 Recursive Tree
15.5.2 Sierpinski Triangles
15.6 Recursion to Non-recursion
15.7 GUI for Turtle Drawing
15.7.1 Using Turtle Graphics to Draw
15.7.2 Function Model
15.7.3 Controller and View
Chapter 16 Other Fun Stuff with Python
16.1 Numbers
16.1.1 Fractions
16.1.2 Decimal
16.1.3 Complex Numbers
16.1.4 Statistics Module
16.1.5 Random Numbers
16.2 Even More on Functions
16.2.1 Having a Varying Number of Parameters
16.2.2 Iterators and Generators
16.2.3 Other Functional Programming Ideas
16.2.4 Some Functional Programming Tools
16.2.5 Decorators: Functions Calling Functions
16.3 Classes
16.3.1 Properties
16.3.2 Serializing an Instance: pickle
16.4 Other Things in Python
16.4.1 Data Types
16.4.2 Built-in Modules
16.4.3 Modules on the Internet
Chapter 17 The End, or Perhaps the Beginning
APPENDICE
S
Appendix A Getting and Using Python
A.1 About Python
A.1.1 History
A.1.2 Python 3
A.1.3 Python Is Free and Portable
A.1.4 Installing Anaconda
A.1.5 Starting Our Python IDE: Spyder
A.1.6 Working with Python
A.1.7 Making a Program
A.2 The IPython Console
A.2.1 Anatomy of an iPython Session
A.2.2 Your Top Three iPython Tips
A.2.3 Completion and the Tab Key
A.2.4 The ? Character
A.2.5 More iPython Tips
A.3 Some Conventions for This Book
A.3.1 Interactive Code
A.3.2 Program: Written Code
A.3.3 Combined Program and Output
A.4 Summary
Appendix B Simple Drawing with Turtle Graphics
B.0.1 What Is a Turtle?
B.0.2 Motion
B.0.3 Drawing
B.0.4 Color
B.0.5 Drawing with Color
B.0.6 Other Commands
B.1 Tidbits
B.1.1 Reset/Close the Turtle Window
Appendix C What’s Wrong with My Code?
C.1 It’s Your Fault!
C.1.1 Kinds of Errors
C.1.2 “Bugs” and Debugging
C.2 Debugging
C.2.1 Testing for Correctness
C.2.2 Probes
C.2.3 Debugging with Spyder Example 1
C.2.4 Debugging Example 1 Using print()
C.2.5 Debugging with Spyder Example 2
C.2.6 More Debugging Tips
C.3 More about Testing
C.3.1 Testing Is Hard!
C.3.2 Importance of Testing
C.3.3 Other Kinds of Testing
C.4 What’s Wrong with My Code?
C.4.1 Chapter 1: Beginnings
C.4.2 Chapter 2: Control
C.4.3 Chapter 4: Strings
C.4.4 Chapter 5: Functions
C.4.5 Chapter 6: Files and Exceptions
C.4.6 Chapter 7: Lists and Tuples
C.4.7 Chapter 8: More Functions
C.4.8 Chapter 9: Dictionaries
C.4.9 Chapter 11: Classes I
C.4.10 Chapter 12: Classes II
Appendix D Pylab: A Plotting and Numeric Tool
D.1 Plotting
D.2 Working with pylab
D.2.1 Plot Command
D.2.2 Colors, Marks, and Lines
D.2.3 Generating X-Values
D.2.4 Plot Properties
D.2.5 Tick Labels
D.2.6 Legend
D.2.7 Bar Graphs
D.2.8 Histograms
D.2.9 Pie Charts
D.2.10 How Powerful Is pylab?
Appendix E Quick Introduction to Web-based User Interfaces
E.0.1 MVC Architecture
E.1 Flask
E.2 QuickStart Flask, Hello World
E.2.1 What Just Happened?
E.2.2 Multiple Routes
E.2.3 Stacked Routes, Passing Address Arguments
E.3 Serving Up Real HTML Pages
E.3.1 A Little Bit of HTML
E.3.2 HTML Tags
E.3.3 Flask Returning Web Pages
E.3.4 Getting Arguments into Our Web Pages
E.4 Active Web Pages
E.4.1 Forms in wtforms
E.4.2 A Good Example Goes a Long Way
E.4.3 Many Fields Example
E.5 Displaying and Updating Images
E.6 Odds and Ends
Appendix F Table of UTF-8 One Byte Encodings
Appendix G Precedence
Appendix H Naming Conventions
H.1 Python Style Elements
H.2 Naming Conventions
H.2.1 Our Added Naming Conventions
H.3 Other Python Conventions
Appendix I Check Yourself Solutions
I.1 Chapter 1
Variables and Assignment
Types and Operators
I.2 Chapter 2
Basic Control Check
Loop Control Check
More Control Check
for and range Check
I.3 Chapter 4
Slicing Check
String Comparison Check
I.4 Chapter 5
Simple Functions Check
I.5 Chapter 6
Exception Check
Function Practice with Strings
I.6 Chapter 7
Basic Lists Check
Lists and Strings Check
Mutable List Check
I.7 Chapter 8
Passing Mutables Check
More on Functions Check
I.8 Chapter 9
Dictionary Check
Set Check
I.9 Chapter 11
Basic Classes Check
Defining Special Methods
I.10 Chapter 12
Check Defining Your Own Operators
I.11 Chapter 14
Basic File Operations
Basic Exception Control
INDEX
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
Y
Z