Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Language Basics

The Processing View

A programming language involves two closely interleaved topics. On one hand, there are the statement constructs that process information inside the computer, with visible effects on the various external devices. On the other hand are the various types of data and relationship structures for organizing the information manipluated by the program.

This part describes the most commonly-used Python statements, sticking with basic numeric data types. Part II, “Data Structures” will present a reasonably complete set of built-in data types and features for Python. While the two are tightly interwoven, we pick the statements as more fundamental because we we can (and will) add new data types. Indeed, the essential thrust of object-oriented programming (covered in Part III, “Data + Processing = Objects”) is the creation of new data types.

Some of the examples in this part refer to the rules of various common casino games. Knowledge of casino gambling is not essential to understanding the language or this part of the book. We don't endorse casino gambling. Indeed, many of the exercises reveal the magnitude of the house edge in most casino games. However, casino games have just the right level of algorithmic complexity to make for excellent programming exercises.

In Chapter 3, Getting Started we'll describe the basics of computer programming, installing a Python interpreter, using Python interactively, and writing simple scripts. In Chapter 4, Simple Numeric Expressions and Output we'll introduce the print statement, and arithmetic expressions including the numeric data types, operators, conversions, and some built-in functions. We'll expand on this in Chapter 5, Advanced Expressions . We'll introduce variables, the assignment statement, and input in Chapter 6, Variables, Assignment and Input , allowing us to create simple input-process-output programs. When we add truth, comparisons, conditional processing, iterative processing and assertions in Chapter 7, Truth, Comparison and Conditional Processing , we'll have all the tools necessary for programming. In Chapter 9, Functions and Chapter 10, Additional Notes On Functions , we'll show how to define and use functions, the first of many tools for organizing programs to make them understandable.

Table of Contents

1. Background and History
History
Features of Python
Comparisons
The Java Yardstick
The Modula-2 Yardstick
2. Python Installation
Windows Installation
Windows Pre-Installation
Windows Installation
Windows Post-Installation
Macintosh Installation
Macintosh Pre-Installation
Macintosh Installation
Macintosh Post-Installation
GNU/Linux and UNIX Overview
YUM Installation
RPM Installation
RPM Pre-Installation
RPM Installation
RPM Post-Installation
"Build from Scratch" Installation
3. Getting Started
Command-Line Interaction
Starting and Stopping Command-Line Python
Entering Python Statements
The IDLE Development Environment
Starting and Stopping
Basic IDLE Operations
The Shell Window
The File Windows
Script Mode
Explicit Command Line
Implicit Command-Line Execution
Another Script Example
Syntax Formalities
Exercises
Command-Line Exercises
IDLE Exercises
Script Exercises
Other Tools
Any Platform
Windows
Macintosh
Style Notes: Wise Choice of File Names
4. Simple Numeric Expressions and Output
The print Statement
print Syntax Overview
print Notes and Hints
Numeric Types and Operators
Integers
Long Integers
Floating-Point Numbers
Complex Numbers
Numeric Conversion Functions
Conversion Function Definitions
Conversion Function Examples
Built-In Functions
Built-In Math Functions
Conversion Functions
Collection Functions
Expression Exercises
Basic Output and Functions
Numeric Types and Expressions
Expression Style Notes
5. Advanced Expressions
Using Modules
The math Module
The random Module
Advanced Expression Exercises
Bit Manipulation Operators
Division Operators
6. Variables, Assignment and Input
Variables
The Assignment Statement
Basic Assignment
Augmented Assignment
Input Functions
The raw_input Function
The input Function
Multiple Assignment Statement
The del Statement
Interactive Mode Revisited
Variable and Assignment Exercises
Variable and Assignment Exercises
Input Function Exercises
Variables and Assignment Style Notes
7. Truth, Comparison and Conditional Processing
Truth and Logic
Truth
Logic
Exercises
Comparisons
Basic Comparisons
Partial Evaluation
Floating-Point Comparisons
Conditional Processing: the if Statement
The if Statement
The elif Clause
The else Clause
The pass Statement
The assert Statement
The if-else Operator
Condition Exercises
Condition Style Notes
8. Looping
Iterative Processing: For All and There Exists
Iterative Processing: The for Statement
Iterative Processing: The while Statement
More Iteration Control: break and continue
Iteration Exercises
Condition and Loops Style Notes
A Digression
9. Functions
Semantics
Function Definition: The def and return Statements
Function Use
Function Varieties
Some Examples
Hacking Mode
More Features
Default Values for Parameters
Providing Argument Values by Keyword
Returning Multiple Values
Function Exercises
Object Method Functions
Functions Style Notes
10. Additional Notes On Functions
Functions and Namespaces
The global Statement
Call By Value and Call By Reference
Function Objects

 
 
  Published under the terms of the Open Publication License Design by Interspire