Table of Content
CHAPTER 1: INTRODUCTION TO PYTHON .......................................1
1.1 Getting Started: Introduction to Python- an interpreted high level
language, interactive mode and script mode .................................................. 2
1.2 Variables and Types-mutable and Immutable variable and Keywords ...... 6
1.3 Operators and Operands in Python .................................................................. 7
1.4 Operator precedence, Expressions and Statements
(Assignment statement) .....................................................................................11
1.5 Taking input (using raw_input() and input()) and
displaying output - print statement ................................................................ 12
1.6 Comments in Python ......................................................................................... 13
Exercise ................................................................................................................ 14
CHAPTER 2: CONDITIONAL AND LOOPING CONSTRUCT ..............15
2.1 if - else statement and nested if – else while, for, use of range
function in for, Nested loops ............................................................................ 16
2.2 break, continue, pass statement ....................................................................... 24
2.3 Use of Compound Expression in conditional construct .............................. 26
2.4 Built-In Function, invoking built in functions ............................................... 27
2.5 Functions from Math, Random, Time & Date Module ................................ 29
2.6 Module (Importing entire module or selected
objects using from statement) .......................................................................... 33
2.7 Composition ....................................................................................................... 33
2.8 User Defined Function: Defining, invoking functions, passing parameters
(default parameter values, keyword arguments) ......................................... 34
2.9 Scope of Variables, Void Functions and Functions Returning
Values Scope of Variables ................................................................................. 38
Exercise ................................................................................................................ 43
xii Python Programming for Beginners
CHAPTER 3: STRINGS .......................................................45
3.1 Creating, Initializing and Accessing the Elements ....................................... 46
3.2 String Operators ................................................................................................. 48
3.3 String built in functions & methods: ............................................................... 51
Exercise ................................................................................................................ 67
CHAPTER 4: STRUCTURED PROGRAMMING:
ITERATION CONTROL FLOW ...........................................................69
4.1 Concept of Mutable Lists, Creating, Initializing and
Accessing the Elements of List ........................................................................ 70
4.2 List Operations (Concatenation, Repetition, Membership,
List Slices), List Comprehensions .................................................................... 72
4.3 List Functions & Methods: append, extend, sort,
remove, reverse, pop ......................................................................................... 74
4.4 Immutable concept, creating, initializing and
accessing the elements in a tuple ..................................................................... 78
4.5 Tuple Functions: cmp(), len(), max(), min(), tuple() ..................................... 79
4.6 Concept of Sets, Creating, Initializing and
Accessing the Elements of Sets ........................................................................ 82
4.7 Sets Operation (Membership, Union, Intersection, Difference,
and Symmetric Difference) ............................................................................... 83
4.8 Concept of Key-Value Pair, Creating, Initializing and
Accessing the Elements in a Dictionary ......................................................... 85
4.9 Traversing, Appending, Updating and Deleting Elements ......................... 87
4.10 Dictionary Functions & Methods: cmp, len, clear(),
has_key(), items(), keys(), update(), values() ................................................. 88
Exercise ................................................................................................................ 92
CHAPTER 5: MODULES .....................................................................93
5.1 Concept of Module: Executing Modules as Scripts,
the Module Search Path, “Compiled” Python Files,
Standard Modules: What is Module? ............................................................. 94
Table of Content xiii
5.2 The dir() Function ................................................................................................ 97
5.3 Package ................................................................................................................. 98
Exercise ...................................................................................................................... 101
CHAPTER 6: I/O AND FILE HANDLING .........................................103
6.1 Output Formatting: .......................................................................................... 104
6.2 Filenames and Paths:........................................................................................ 106
6.3 Reading and Writing Files:.............................................................................. 109
Exercise:.......................................................................................................................113
CHAPTER 7: ERRORS AND EXCEPTIONS .......................................115
7.1 Syntax Errors, Exceptions:................................................................................116
7.2 Handling Exceptions:........................................................................................118
7.3 Python Exception(Except with No Exception) Example: .......................... 120
7.4 Raise an Exception:........................................................................................... 123
7.5 User-defined Exceptions:................................................................................. 124
7.6 Clean-Up Actions (Try ... Finally):.................................................................. 125
Exercise:...................................................................................................................... 128
CHAPTER 8: INTRODUCTION TO OBJECT ORIENTED
CONCEPTS IN PYTHON ..................................................................129
8.1 Object Oriented concepts ................................................................................ 130
8.3 Classes, Class Objects, Instance Objects, Method Objects, Class and
Instance Variables: Class and Instance Variables in Python ...................... 131
8.4 Inheritance ........................................................................................................ 134
Exercise ...................................................................................................................... 137
There are no comments on this title.