Foreword |
|
xix | |
Foreword |
|
xxi | |
Preface |
|
xxii | |
Acknowledgments |
|
xxv | |
Authors |
|
xxvii | |
|
SECTION I Python Fundamentals |
|
|
|
Chapter 1 Interaction with Python |
|
|
3 | (28) |
|
|
3 | (1) |
|
|
3 | (1) |
|
1.2 Variables and Identifiers |
|
|
3 | (5) |
|
1.2.1 How to Name Identifiers |
|
|
4 | (1) |
|
1.2.2 Use of Descriptive Identifiers and Comments |
|
|
4 | (1) |
|
|
5 | (1) |
|
1.2.3.1 Numeric Datatypes |
|
|
6 | (1) |
|
|
7 | (1) |
|
1.2.3.3 Sequence Datatypes |
|
|
7 | (1) |
|
|
7 | (1) |
|
|
8 | (1) |
|
|
8 | (1) |
|
|
8 | (2) |
|
1.4 Statement and Expression |
|
|
10 | (1) |
|
|
10 | (3) |
|
|
13 | (2) |
|
1.7 Formatting Output Statements |
|
|
15 | (10) |
|
|
15 | (2) |
|
|
17 | (3) |
|
1.7.3 String Formatting with formatf) |
|
|
20 | (2) |
|
1.7.4 Numbers Formatting with format() |
|
|
22 | (3) |
|
|
25 | (6) |
|
Multiple Choice Questions |
|
|
26 | (2) |
|
|
28 | (1) |
|
|
28 | (1) |
|
Answer to Multiple Choice Questions |
|
|
29 | (2) |
|
|
31 | (26) |
|
|
31 | (1) |
|
|
31 | (1) |
|
|
31 | (19) |
|
2.2.1 Assignment Operator |
|
|
31 | (2) |
|
2.2.2 Arithmetic Operators |
|
|
33 | (4) |
|
2.2.2.1 Precedence of Arithmetic Operators |
|
|
37 | (2) |
|
2.2.3 Relational Operators |
|
|
39 | (1) |
|
|
40 | (1) |
|
|
40 | (1) |
|
|
41 | (1) |
|
|
41 | (1) |
|
2.2.5 Increment and Decrement Operators |
|
|
42 | (1) |
|
|
42 | (1) |
|
2.2.6.1 Bitwise AND Operator (&) |
|
|
42 | (2) |
|
2.2.6.2 Bitwise OR Operator (|) |
|
|
44 | (1) |
|
2.2.6.3 Bitwise XOR Operator (ˆ) |
|
|
44 | (1) |
|
2.2.6.4 Bitwise Complement (~) |
|
|
45 | (1) |
|
2.2.6.5 Bitwise Left Shift (<<) |
|
|
46 | (1) |
|
2.2.6.6 Bitwise Right Shift (>>) |
|
|
46 | (1) |
|
2.2.7 Membership Operators |
|
|
47 | (1) |
|
|
48 | (2) |
|
2.2.9 Precedence of all Operators |
|
|
50 | (1) |
|
|
50 | (7) |
|
Multiple Choice Questions |
|
|
53 | (3) |
|
|
56 | (1) |
|
|
56 | (1) |
|
Answer to Multiple Choice Questions |
|
|
56 | (1) |
|
Chapter 3 Control Structures |
|
|
57 | (38) |
|
|
57 | (1) |
|
|
57 | (1) |
|
3.2 Conditional Statements |
|
|
58 | (11) |
|
3.2.1 Conditional if-else |
|
|
58 | (3) |
|
3.2.2 Conditional if-elif-else |
|
|
61 | (4) |
|
3.2.3 Nested if-elif-else Statements |
|
|
65 | (1) |
|
|
66 | (3) |
|
|
69 | (15) |
|
|
69 | (3) |
|
|
72 | (2) |
|
3.3.2.1 The range() Function |
|
|
74 | (3) |
|
3.3.3 Continue, Break and Pass |
|
|
77 | (1) |
|
3.3.3.1 Continue Statement |
|
|
77 | (2) |
|
|
79 | (2) |
|
|
81 | (1) |
|
|
82 | (2) |
|
3.4 Loopi ng through two Lists |
|
|
84 | (1) |
|
|
84 | (11) |
|
|
86 | (1) |
|
Multiple Choice Questions |
|
|
87 | (5) |
|
|
92 | (1) |
|
|
92 | (1) |
|
Answer to Multiple Choice Questions |
|
|
93 | (2) |
|
|
95 | (32) |
|
|
95 | (1) |
|
|
95 | (1) |
|
|
95 | (32) |
|
|
96 | (1) |
|
4.2.1.1 Creating an Empty String |
|
|
96 | (1) |
|
4.2.1.2 Creating a String from Numbers |
|
|
97 | (1) |
|
4.2.1.3 Creating a String from List and Tuple |
|
|
97 | (1) |
|
|
98 | (1) |
|
4.2.2.1 Membership in String |
|
|
99 | (1) |
|
|
99 | (1) |
|
|
100 | (1) |
|
|
100 | (2) |
|
|
102 | (4) |
|
4.2.5 String Functions and Methods |
|
|
106 | (1) |
|
|
106 | (1) |
|
|
106 | (1) |
|
|
106 | (1) |
|
|
107 | (1) |
|
|
108 | (1) |
|
|
108 | (1) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
109 | (1) |
|
|
110 | (1) |
|
|
111 | (1) |
|
|
111 | (1) |
|
|
112 | (1) |
|
|
113 | (1) |
|
|
113 | (1) |
|
4.2.6.1 String Slicing with Negative Index |
|
|
114 | (1) |
|
4.2.6.2 String Slicing with Step |
|
|
115 | (1) |
|
4.2.6.3 String Slicing Default Index |
|
|
116 | (3) |
|
|
119 | (1) |
|
Multiple Choice Questions |
|
|
120 | (5) |
|
|
125 | (1) |
|
|
125 | (1) |
|
Answer to Multiple Choice Questions |
|
|
126 | (1) |
|
|
127 | (56) |
|
|
127 | (1) |
|
|
127 | (1) |
|
|
127 | (29) |
|
|
128 | (1) |
|
5.2.1.1 Creating an Empty List |
|
|
128 | (1) |
|
5.2.1.2 Creating a List from a String |
|
|
128 | (1) |
|
5.2.1.3 Creating a List by Range Function |
|
|
128 | (1) |
|
5.2.1.4 Creating a List from Another List |
|
|
129 | (1) |
|
|
130 | (1) |
|
5.2.2.1 Concatenation (+) |
|
|
130 | (1) |
|
|
130 | (1) |
|
|
130 | (1) |
|
5.2.3.1 Membership in List |
|
|
131 | (1) |
|
5.2.4 List Functions and Methods |
|
|
132 | (1) |
|
|
132 | (1) |
|
|
132 | (2) |
|
|
134 | (1) |
|
|
135 | (1) |
|
|
135 | (1) |
|
|
136 | (1) |
|
|
136 | (1) |
|
|
137 | (1) |
|
|
138 | (1) |
|
|
139 | (1) |
|
|
139 | (1) |
|
|
140 | (1) |
|
|
141 | (2) |
|
|
143 | (1) |
|
|
143 | (1) |
|
|
144 | (1) |
|
|
144 | (1) |
|
|
144 | (1) |
|
|
145 | (1) |
|
|
146 | (2) |
|
|
148 | (1) |
|
5.2.5.1 List Slicing with Negative Index |
|
|
149 | (2) |
|
5.2.5.2 List Slicing with Step |
|
|
151 | (1) |
|
5.2.5.3 List Slicing Default Index |
|
|
152 | (3) |
|
5.2.6 Difference between Assignment and Copying a List |
|
|
155 | (1) |
|
5.3 Multi-Dimensional Lists |
|
|
156 | (5) |
|
5.3.1 Retrieval from Multi-Dimensional Lists |
|
|
156 | (5) |
|
|
161 | (7) |
|
|
161 | (1) |
|
5.4.1.1 Creating a Tuple with no Item |
|
|
161 | (1) |
|
5.4.1.2 Creating a Tuple with a Single Item |
|
|
162 | (1) |
|
|
163 | (1) |
|
5.4.1.4 Creating a Tuple from List |
|
|
163 | (1) |
|
5.4.1.5 Creating a Tuple from a String |
|
|
163 | (1) |
|
|
164 | (1) |
|
5.4.2.1 Concatenation (+) Operation |
|
|
164 | (1) |
|
5.4.2.2 Repetition (*) Operation |
|
|
164 | (1) |
|
|
165 | (1) |
|
5.4.4 Accessing Objects in Tuple |
|
|
166 | (1) |
|
5.4.4.1 Membership in Tuple |
|
|
166 | (1) |
|
|
167 | (1) |
|
5.4.6 Tuple Functions and Methods |
|
|
168 | (1) |
|
|
168 | (1) |
|
5.5 Advantages of Tuple over List |
|
|
168 | (15) |
|
Multiple Choice Questions - List |
|
|
170 | (5) |
|
Multiple Choice Questions - Tuple |
|
|
175 | (5) |
|
Descriptive Questions - List |
|
|
180 | (1) |
|
Descriptive Questions - Tuple |
|
|
180 | (1) |
|
Programming Questions - List |
|
|
180 | (1) |
|
Programming Questions - Tuple |
|
|
181 | (1) |
|
Answer to Multiple Choice Questions - List |
|
|
181 | (1) |
|
Answer to Multiple Choice Questions - Tuple |
|
|
181 | (2) |
|
|
183 | (18) |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
183 | (18) |
|
6.2.1 Creating a Dictionary |
|
|
184 | (1) |
|
6.2.1.1 Creating a Dictionary with no item |
|
|
184 | (1) |
|
6.2.1.2 Creating a Dictionary with { } |
|
|
185 | (1) |
|
6.2.1.3 Creating a Dictionary with dict() |
|
|
185 | (1) |
|
6.2.1.4 Creating a Default Dictionary |
|
|
186 | (1) |
|
6.2.1.5 Creating a Dictionary from a List |
|
|
186 | (1) |
|
6.2.1.6 Insertion of a New Key-Value |
|
|
186 | (1) |
|
6.2.2 Dictionary Assignment |
|
|
187 | (1) |
|
6.2.3 Accessing Dictionary |
|
|
187 | (1) |
|
|
188 | (1) |
|
|
188 | (1) |
|
|
188 | (2) |
|
6.2.3.4 Membership in Dictionary |
|
|
190 | (1) |
|
|
190 | (1) |
|
|
190 | (2) |
|
|
192 | (1) |
|
|
192 | (1) |
|
|
192 | (1) |
|
|
193 | (1) |
|
Multiple Choice Questions |
|
|
194 | (4) |
|
|
198 | (1) |
|
|
198 | (1) |
|
Answer to Multiple Choice Questions |
|
|
199 | (2) |
|
|
201 | (20) |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
201 | (20) |
|
|
202 | (1) |
|
7.2.1.1 Creating an Empty Set |
|
|
202 | (1) |
|
7.2.1.2 Creating a Set from a List, Tuples and String |
|
|
203 | (1) |
|
7.2.1.3 Creating a Set from a Dictionary |
|
|
203 | (1) |
|
7.2.2 Accessing Set Elements |
|
|
204 | (1) |
|
7.2.2.1 Membership in Set |
|
|
204 | (1) |
|
|
204 | (1) |
|
|
205 | (1) |
|
|
205 | (1) |
|
|
206 | (1) |
|
|
207 | (1) |
|
7.2.3.5 Symmetric Difference |
|
|
208 | (1) |
|
7.2.3.6 Equivalent Set and Not Equivalent |
|
|
208 | (1) |
|
7.2.3.7 Subset and Superset |
|
|
209 | (1) |
|
7.2.3.8 Proper Subset and Proper Superset |
|
|
210 | (1) |
|
7.2.4 Set Function and Methods |
|
|
210 | (1) |
|
|
211 | (1) |
|
|
211 | (1) |
|
|
212 | (1) |
|
|
212 | (1) |
|
|
213 | (1) |
|
|
213 | (1) |
|
|
214 | (1) |
|
Multiple Choice Questions |
|
|
215 | (3) |
|
|
218 | (1) |
|
|
218 | (1) |
|
Answer to Multiple Choice Questions |
|
|
219 | (2) |
|
|
221 | (50) |
|
|
221 | (1) |
|
|
221 | (1) |
|
|
221 | (4) |
|
8.3 Parameterized Function |
|
|
225 | (9) |
|
8.3.1 Positional and Keyword Parameters |
|
|
227 | (2) |
|
|
229 | (1) |
|
8.3.3 Function with a Variable Number of Arguments |
|
|
230 | (4) |
|
|
234 | (3) |
|
8.5 Namespace and Scope of a Variable |
|
|
237 | (4) |
|
|
241 | (1) |
|
|
242 | (5) |
|
|
244 | (1) |
|
|
245 | (1) |
|
|
246 | (1) |
|
|
246 | (1) |
|
|
247 | (2) |
|
|
249 | (6) |
|
|
250 | (3) |
|
|
253 | (1) |
|
8.9.3 User-Defined Module |
|
|
254 | (1) |
|
|
255 | (3) |
|
|
258 | (5) |
|
8.11.1 Passing a Parameter to a Decorator |
|
|
261 | (1) |
|
8.11.2 Decorator Chaining |
|
|
262 | (1) |
|
8.12 Some Special Methods and Attributes |
|
|
263 | (8) |
|
|
263 | (1) |
|
|
264 | (1) |
|
|
264 | (1) |
|
Multiple Choice Questions |
|
|
265 | (5) |
|
|
270 | (1) |
|
|
270 | (1) |
|
Answer to Multiple Choice Questions |
|
|
270 | (1) |
|
|
271 | (20) |
|
|
271 | (1) |
|
|
271 | (1) |
|
|
271 | (5) |
|
9.2.1 File Opening and Closing |
|
|
271 | (1) |
|
|
272 | (1) |
|
|
273 | (1) |
|
|
274 | (1) |
|
9.2.5 Binary File Reading/Writing |
|
|
275 | (1) |
|
9.2.6 CSV File Reading/Writing |
|
|
275 | (1) |
|
|
276 | (2) |
|
9.4 Some More File Operations |
|
|
278 | (1) |
|
9.5 Operating System-Related Operations |
|
|
279 | (3) |
|
|
282 | (1) |
|
|
282 | (9) |
|
|
283 | (1) |
|
Multiple Choice Questions |
|
|
284 | (3) |
|
|
287 | (1) |
|
|
287 | (1) |
|
Answer to Multiple Choice Questions |
|
|
287 | (4) |
|
SECTION II Object Oriented Concepts in Python |
|
|
|
Chapter 10 Classes and Objects |
|
|
291 | (46) |
|
|
291 | (1) |
|
10.1 Introduction to Object-Oriented Programming |
|
|
291 | (2) |
|
|
293 | (9) |
|
|
293 | (1) |
|
10.2.2 Generating an Object |
|
|
294 | (1) |
|
10.2.3 The init_(), new_() and del_() Methods |
|
|
295 | (1) |
|
|
296 | (2) |
|
|
298 | (2) |
|
|
300 | (2) |
|
10.3 Variables and Methods |
|
|
302 | (8) |
|
10.3.1 Variables (Attributes) |
|
|
302 | (1) |
|
10.3.1.1 Object Variables (Instance Variables) |
|
|
303 | (2) |
|
10.3.1.2 Class Variables (Static Variables) |
|
|
305 | (3) |
|
10.3.2 Accessing Variables |
|
|
308 | (1) |
|
10.3.2.1 Accessing the Variable by Object Reference |
|
|
308 | (1) |
|
10.3.2.2 Accessing the Variable by Class Name |
|
|
309 | (1) |
|
10.3.2.3 Accessing the Static Variable Outside the Class by Class Name |
|
|
310 | (1) |
|
10.4 Public, Private and Protected Variables |
|
|
310 | (4) |
|
10.4.1 Variable Starts Without Any (Underscore) Symbol |
|
|
310 | (1) |
|
10.4.2 Variable Starts with (Single Underscore) Symbol |
|
|
311 | (1) |
|
10.4.3 Variable Starts with (Two Underscores) symbols |
|
|
312 | (2) |
|
|
314 | (3) |
|
|
314 | (1) |
|
|
315 | (1) |
|
|
316 | (1) |
|
10.6 Class Inside a Class (Inner Class) |
|
|
317 | (4) |
|
10.6.1 Object of the Inner Class Is Created Inside the Outer Class |
|
|
317 | (1) |
|
10.6.2 Object of the Inner Class Is Created Outside the Outer Class |
|
|
318 | (1) |
|
10.6.3 Accessing Attributes of Inner Class |
|
|
318 | (1) |
|
10.6.3.1 Accessing the Attributes of Inner Class Outside the Class |
|
|
319 | (1) |
|
10.6.3.2 Accessing the Attributes of Inner Class in the Outer Class |
|
|
319 | (1) |
|
10.6.3.3 Accessing the Attributes of Inner Class Outside the Outer Class |
|
|
320 | (1) |
|
10.6.3.4 Accessing the Attributes of Inner Class When Inner Class and Outer Class Have the Same Method |
|
|
320 | (1) |
|
10.7 Some Special Methods and Attributes |
|
|
321 | (16) |
|
|
321 | (1) |
|
|
322 | (1) |
|
|
323 | (1) |
|
|
324 | (1) |
|
|
324 | (1) |
|
10.7.6 Setattr(obj, name, value) |
|
|
325 | (1) |
|
|
326 | (1) |
|
|
327 | (1) |
|
|
328 | (1) |
|
|
329 | (1) |
|
|
329 | (2) |
|
Multiple Choice Questions |
|
|
331 | (4) |
|
|
335 | (1) |
|
|
335 | (1) |
|
Answer to Multiple Choice Questions |
|
|
335 | (2) |
|
|
337 | (28) |
|
|
337 | (1) |
|
|
337 | (8) |
|
11.1.1 Single-Level inheritance |
|
|
338 | (2) |
|
11.1.2 Multi-Level Inheritance |
|
|
340 | (2) |
|
11.1.3 Multiple Inheritance |
|
|
342 | (2) |
|
11.1.4 Hierarchical Inheritance |
|
|
344 | (1) |
|
11.1.5 Hybrid inheritance |
|
|
345 | (1) |
|
11.2 Initialization in Inheritance |
|
|
345 | (5) |
|
11.2.1 Init_() for the Child Class Only Is Defined |
|
|
346 | (1) |
|
11.2.2 Init_() for the Base Class Only Is Defined |
|
|
346 | (1) |
|
11.2.3 Init_() for Both Sub Class and Super Class Is Denned |
|
|
347 | (3) |
|
11.3 Method Resolution Order |
|
|
350 | (5) |
|
|
355 | (10) |
|
|
355 | (1) |
|
|
355 | (1) |
|
|
356 | (1) |
|
Multiple Choice Questions |
|
|
357 | (5) |
|
|
362 | (1) |
|
|
363 | (1) |
|
Answer to Multiple Choice Questions |
|
|
363 | (2) |
|
|
365 | (20) |
|
|
365 | (1) |
|
|
365 | (11) |
|
|
367 | (3) |
|
12.1.2 Operator Overloading |
|
|
370 | (2) |
|
12.1.3 Method Overloading |
|
|
372 | (2) |
|
|
374 | (2) |
|
|
376 | (9) |
|
|
379 | (1) |
|
Multiple Choice Questions |
|
|
380 | (4) |
|
|
384 | (1) |
|
|
384 | (1) |
|
Answer to Multiple Choice Questions |
|
|
384 | (1) |
|
Chapter 13 Abstract Class, Aggregation, Composition |
|
|
385 | (18) |
|
|
385 | (1) |
|
13.1 Introduction - Abstract Class |
|
|
385 | (1) |
|
13.2 Abstract Class and Abstract Method |
|
|
385 | (3) |
|
|
388 | (8) |
|
13.3.1 Association Relationship |
|
|
388 | (2) |
|
13.3.2 Aggregation (Uses a) Relationship |
|
|
390 | (3) |
|
13.3.3 Composition (Has a) Relationship |
|
|
393 | (3) |
|
13.4 Difference between Inheritance and Association |
|
|
396 | (1) |
|
13.5 Difference between Aggregation and Composition |
|
|
396 | (7) |
|
|
396 | (2) |
|
Multiple Choice Questions |
|
|
398 | (3) |
|
|
401 | (1) |
|
|
401 | (1) |
|
Answer to Multiple Choice Questions |
|
|
401 | (2) |
|
Chapter 14 Exception Handling |
|
|
403 | (24) |
|
|
403 | (1) |
|
14.1 Errors and Exceptions |
|
|
403 | (1) |
|
14.2 The try:, except:, else: and finally: Block |
|
|
404 | (6) |
|
14.2.1 The try: and except: Block |
|
|
405 | (1) |
|
14.2.2 The try:, except: and else: Block |
|
|
406 | (2) |
|
14.2.3 The try:, except:, else: and finally: Block |
|
|
408 | (1) |
|
14.2.4 Mentioning the Error Description |
|
|
409 | (1) |
|
14.3 The Exception Hierarchy |
|
|
410 | (5) |
|
14.4 Exception in a Function |
|
|
415 | (1) |
|
14.5 The Raised Exception |
|
|
416 | (2) |
|
14.6 User Defined Exceptions |
|
|
418 | (2) |
|
|
420 | (7) |
|
|
421 | (1) |
|
Multiple Choice Questions |
|
|
421 | (4) |
|
|
425 | (1) |
|
|
425 | (1) |
|
Answer to Multiple Choice Questions |
|
|
426 | (1) |
Index |
|
427 | |