Python: Visual QuickStart Guide
暫譯: Python:快速入門指南

Chris Fehily

  • 出版商: Peachpit Press
  • 出版日期: 2001-11-05
  • 售價: $770
  • 貴賓價: 9.8$755
  • 語言: 英文
  • 頁數: 440
  • 裝訂: Paperback
  • ISBN: 0201748843
  • ISBN-13: 9780201748840
  • 相關分類: Python程式語言
  • 無法訂購

買這商品的人也買了...

相關主題

商品描述

Named after the Monty Python comedy troupe, Python is an interpreted, open-source, object-oriented programming language. It's also free and runs portably on Windows, Mac OS, Unix, and other operating systems. Python can be used for all manner of programming tasks, from CGI scripts to full-fledged applications. It is gaining popularity among programmers in part because it is easier to read (and hence, debug) than most other programming languages, and it's generally simpler to install, learn, and use. Its line structure forces consistent indentation. Its syntax and semantics make it suitable for simple scripts and large programs. Its flexible data structures and dynamic typing allow you to get a lot done in a few lines. To learn it, you'll need is some basic programming experience and a copy of Python: Visual QuickStart Guide.

In patented Visual QuickStart Guide fashion, the book doesn't just tell you how to use Python to develop applications, it shows you, breaking Python into easy-to-digest, step-by-step tasks and providing example code. Python: Visual QuickStart Guide emphasizes the core language and libraries, which are the building blocks for programs. Author Chris Fehily starts with the basics - expressions, statements, numbers, strings - then moves on to lists, dictionaries, functions, and modules before wrapping things up with straightforward discussions of exceptions and classes. Some additional topics covered include:- Object-oriented programming- Working in multiple operating systems- Structuring large programs- Comparing Python to C, Perl, and Java- Handling errors gracefully.

Table of Contents

1. Getting Started.

Getting Python. Reading Python Documentation. Opening a Command-Prompt Window. Setting Your Path. Using Python Environment Variables. Running Programs in Interactive Mode. Running Programs in Script Mode. Using IDLE. Specifying Command-Line Options. Passing Arguments to a Script.


2. Expressions and Statements.

Documenting Programs. Naming Variables. Creating Expressions. Creating Expression Statements. Creating Variables. Deleting Variables. Printing Objects. Determining an Object's Identity. Creating References to the Same Object. Determining an Object's Type. Using Boolean Operators. Using Comparison Operators. Chaining Comparisons. Determining the Order of Evaluation. Summarizing Objects.


3. Working with Numbers.

Understanding the Types of Numbers. Understanding Promotion. Performing Basic Arithmetic. Raising a Number to a Power. Getting the Remainder of a Division. Getting the Quotient of a Division. Controlling Calculation Order. Making Augmented Assignments. Converting Among Number Types. Comparing Numbers. Using Mathematical Functions. Using Advanced Mathematical Functions. Generating Random Numbers.


4. Working with Strings.

Creating a String. Inserting Special Characters into a String. Creating a Unicode String. Finding the Length of a String. Indexing a String (Extracting a Character). Slicing a String (Extracting a Substring). Concatenating Strings. Repeating a String. Using String Methods and Functions. Changing String Case. Testing a String. Trimming and Justifying a String. Searching for Substrings. Replacing Substrings. Translating a String. Splitting and Joining Strings. Performing List Operations on a String. Converting a String. Comparing Strings. Printing Formatted Strings.


5. Working with Lists and Tuples.

Creating a List or Tuple. Finding the Length of a List or Tuple. Indexing a List or Tuple (Extracting an Item). Slicing a List or Tuple (Extracting a Segment). Copying a List or Tuple. Concatenating Lists or Tuples. Repeating a List or Tuple. Converting a List or Tuple. Comparing Lists or Tuples. Testing List or Tuple Membership. Modifying a List. Replacing List Items. Counting Matching List Values. Searching a List. Adding List Items. Removing List Items. Sorting a List. Inserting Items into a Sorted List. Defining a Custom List Sort Order. Reversing a List.


6. Working with Dictionaries.

Using Dictionary Operators and Methods. Creating a Dictionary. Printing a Dictionary. Getting a Value by Using a Key. Getting All of a Dictionary's Values. Getting All of a Dictionary's Keys. Getting All of a Dictionary's Key-Value Pairs. Determining Whether a Key Exists. Counting a Dictionary's Key-Value Pairs. Adding or Replacing a Key-Value Pair. Removing a Key-Value Pair. Removing a Random Key-Value Pair. Clearing or Deleting a Dictionary. Combining Dictionaries. Copying a Dictionary. Converting a Dictionary 2. Comparing Dictionaries. Sorting a Dictionary. Storing Computed Values in a Dictionary.


7. Control Flow Statements.

Splitting Statements Across Lines. Creating Compound Statements. Using pass to Create a Null Statement. Indenting Blocks of Statements. Putting Multiple Statements on a Line. Using if Conditionals. Using if-else Conditionals. Using if-elif-else Conditionals. Using while Loops. Using while-else Loops. Using for Loops. Using for-else Loops. Looping over a Range of Integers. Skipping Part of a Loop Iteration. Exiting a Loop.


8. Functions.

Defining a Function. Documenting a Function. Calling a Function. Returning a Value from a Function. Returning Multiple Values from a Function. Specifying Positional Arguments. Specifying Default Parameter Values. Specifying Keyword Arguments. Specifying an Arbitrary Number of Positional Arguments. Specifying an Arbitrary Number of Keyword Arguments. Combining Argument-Passing Techniques. Creating Recursive Functions. Passing Mutable and Immutable Arguments to Functions. Declaring Global Variables. Assigning a Function to a Variable. Using Functional Programming Tools. Using lambda Expressions to Create Functions. Using apply to Call a Function. Using map to Apply a Function to Sequence Items. Using zip to Group Sequence Items. Using filter to Remove Sequence Items Conditionally. Using reduce to Reduce a Sequence. Using List Comprehensions to Create Lists.


9. Modules.

Structuring a Module. Creating a Module. Documenting a Module. Loading a Module with import. Accessing Attributes. Listing an Object's Attributes. Manipulating Attributes. Loading Specific Module Names with from. Loading a Module Under a Different Name with as. Enabling Language Features. Reloading a Module with reload. Specifying the Module Search Path. Determining Whether a Module Is Running As a Program. Determining Which Modules Are Loaded. Understanding Namespaces. Accessing Namespaces. Understanding Scoping Rules. Nesting Functions. Grouping Modules into Packages. Terminating a Program Explicitly. Running Code Programmatically.


10. Files.

Opening a File. Reading from a File. Writing to a File. Closing a File. Changing Position in a File. Truncating a File. Getting File Object Information. Printing to a File. Accessing Standard Input and Output Files. Prompting for User Input. Using the File System. Accessing Environment Variables. Changing the Working Directory. Listing Directory Contents. Creating a Directory. Removing a Directory. Renaming a File or Directory. Removing a File. Getting Path Information. Getting File Information. Splitting Paths. Joining Paths. Saving Objects As Files.


11. Exceptions.

Understanding the Exception Hierarchy. Handling an Exception. Ignoring an Exception. Getting an Exception's Argument. Handling All Exceptions. Running Code in the Absence of an Exception. Handling Multiple Exceptions. Running Mandatory Cleanup Code. Raising an Exception Explicitly. Creating User-Defined Exceptions. Making an Assertion.


12. Classes.

Understanding OOP Terminology. Defining a Class. Documenting a Class. Accessing Built-In Class Attributes. Creating an Instance. Accessing Built-In Instance Attributes. Creating Class Variables. Using Special Methods to Overload Standard Behavior. Creating Instance Variables with an Initialization Method. Destroying an Instance. Creating a String Representation of an Instance. Setting the Truth Value of an Instance. Comparing Instances. Accessing Instance Attributes. Treating an Instance Like a List or Dictionary. Performing Mathematical Operations on Instances. Calling an Instance. Defining and Invoking a Custom Method. Deriving New Classes from Existing Classes. Hiding Private Data. Determining Class Membership.


Appendix.

Learning Python. Getting Support. Editing and Debugging Code. Programming Resources.


Index.

商品描述(中文翻譯)

命名自蒙提·派森(Monty Python)喜劇團體,Python 是一種解釋型、開源、物件導向的程式語言。它是免費的,並且可以在 Windows、Mac OS、Unix 和其他作業系統上可攜式運行。Python 可用於各種程式設計任務,從 CGI 腳本到完整的應用程式。它在程式設計師中越來越受歡迎,部分原因是它比大多數其他程式語言更易於閱讀(因此也更易於除錯),而且通常安裝、學習和使用都更簡單。它的行結構強制一致的縮排。它的語法和語義使其適合簡單的腳本和大型程式。其靈活的資料結構和動態類型使您能夠在幾行程式碼中完成大量工作。要學習它,您需要一些基本的程式設計經驗和一本《Python: Visual QuickStart Guide》。

本書以專利的《Visual QuickStart Guide》風格,不僅告訴您如何使用 Python 開發應用程式,還展示了如何逐步分解 Python,將其分為易於消化的任務並提供範例程式碼。《Python: Visual QuickStart Guide》強調核心語言和庫,這些是程式的基礎構建塊。作者克里斯·費希利(Chris Fehily)從基礎開始 - 表達式、語句、數字、字串 - 然後轉向列表、字典、函數和模組,最後以對例外和類的簡單討論作結。還涵蓋了一些額外主題,包括:
- 物件導向程式設計
- 在多個作業系統中工作
- 結構化大型程式
- 將 Python 與 C、Perl 和 Java 進行比較
- 優雅地處理錯誤。

目錄

1. 開始使用
- 獲取 Python。閱讀 Python 文檔。打開命令提示字元窗口。設置您的路徑。使用 Python 環境變數。在互動模式下運行程式。在腳本模式下運行程式。使用 IDLE。指定命令行選項。將參數傳遞給腳本。

2. 表達式和語句
- 註解程式。命名變數。創建表達式。創建表達式語句。創建變數。刪除變數。打印物件。確定物件的身份。創建對同一物件的引用。確定物件的類型。使用布林運算子。使用比較運算子。鏈接比較。確定評估順序。總結物件。

3. 處理數字
- 理解數字的類型。理解提升。執行基本算術。將數字提升到某個次方。獲取除法的餘數。獲取除法的商。控制計算順序。進行增強賦值。在數字類型之間轉換。比較數字。使用數學函數。使用高級數學函數。生成隨機數。

4. 處理字串
- 創建字串。將特殊字符插入字串。創建 Unicode 字串。查找字串的長度。索引字串(提取字符)。切片字串(提取子字串)。連接字串。重複字串。使用字串方法和函數。改變字串大小寫。測試字串。修剪和對齊字串。搜索子字串。替換子字串。翻譯字串。拆分和連接字串。在字串上執行列表操作。轉換字串。比較字串。打印格式化字串。

5. 處理列表和元組
- 創建列表或元組。查找列表或元組的長度。索引列表或元組(提取項目)。切片列表或元組(提取段落)。複製列表或元組。連接列表或元組。重複列表或元組。轉換列表或元組。比較列表或元組。測試列表或元組的成員資格。修改列表。替換列表項目。計算匹配的列表值。搜索列表。添加列表項目。刪除列表項目。排序列表。將項目插入已排序的列表。定義自訂列表排序順序。反轉列表。

6. 處理字典
- 使用字典運算子和方法。創建字典。打印字典。通過鍵獲取值。獲取字典的所有值。獲取字典的所有鍵。獲取字典的所有鍵值對。確定鍵是否存在。計算字典的鍵值對。添加或替換鍵值對。刪除鍵值對。刪除隨機鍵值對。清空或刪除字典。合併字典。複製字典。轉換字典。比較字典。排序字典。在字典中存儲計算值。

7. 控制流程語句
- 跨行拆分語句。創建複合語句。使用 pass 創建空語句。縮排語句塊。在一行中放置多個語句。使用 if 條件語句。使用 if-else 條件語句。使用 if-elif-else 條件語句。使用 while 循環。使用 while-else 循環。使用 for 循環。使用 for-else 循環。遍歷整數範圍。跳過循環迭代的一部分。退出循環。

8. 函數
- 定義函數。註解函數。調用函數。從函數返回值。從函數返回多個值。指定位置參數。指定預設參數值。指定關鍵字參數。指定任意數量的位置參數。指定任意數量的關鍵字參數。結合參數傳遞技術。創建遞歸函數。將可變和不可變參數傳遞給函數。聲明全域變數。將函數賦值給變數。使用函數式編程工具。使用 lambda 表達式創建函數。使用 apply 調用函數。使用 map 將函數應用於序列項目。使用 zip 將序列項目分組。使用 filter 有條件地移除序列項目。使用 reduce 縮減序列。使用列表推導式創建列表。

9. 模組
- 結構化模組。創建模組。註解模組。使用 import 加載模組。訪問屬性。列出物件的屬性。操作屬性。使用 from 加載特定模組名稱。使用 as 以不同名稱加載模組。啟用語言特性。使用 reload 重新加載模組。指定模組搜索路徑。確定模組是否作為程式運行。確定哪些模組已加載。理解命名空間。訪問命名空間。理解範圍規則。嵌套函數。將模組分組為包。顯式終止程式。以程式化方式運行程式碼。

10. 檔案
- 打開檔案。從檔案中讀取。寫入檔案。關閉檔案。改變檔案中的位置。截斷檔案。獲取檔案物件資訊。打印到檔案。訪問標準輸入和輸出檔案。提示用戶輸入。使用檔案系統。訪問環境變數。改變工作目錄。列出目錄內容。創建目錄。刪除目錄。重新命名檔案或目錄。刪除檔案。獲取路徑資訊。獲取檔案資訊。拆分路徑。連接路徑。將物件保存為檔案。

11. 例外
- 理解例外層級。處理例外。忽略例外。獲取例外的參數。處理所有例外。在沒有例外的情況下運行程式碼。處理多個例外。運行強制清理程式碼。顯式引發例外。創建使用者定義的例外。進行斷言。

12. 類
- 理解物件導向程式設計術語。定義類。註解類。訪問內建類屬性。創建實例。訪問內建實例屬性。創建類變數。使用特殊方法重載標準行為。使用初始化方法創建實例變數。銷毀實例。創建實例的字串表示。設置實例的真值。比較實例。訪問實例屬性。將實例視為列表或字典。對實例執行數學運算。調用實例。定義和調用自訂方法。從現有類派生新類。隱藏私有數據。確定類成員資格。

附錄
- 學習 Python。獲取支援。編輯和除錯程式碼。程式設計資源。

索引