Python Programming delineates the fundamentals of Python language and provides an insight to Python’s role in domains such as the Web, GUI and databases. It focuses on the object oriented programming nature of Python and shows how Python language can be used to develop clean and efficient programs. Designed as a self-learning kit for undergraduate students of computer science, the book has a rich pedagogy that includes fill-in-the-blanks, true/false, MCQs, short- and long-answer type questions, and debugging exercises to hone the learner’s skills in Python programming.
Ch Satyanarayana is Professor, Department of CSE, and Director of Academics and Planning, JNTU Kakinada
M Radhika Mani is Head of the Department of Computer Science and Engineering, Pragati Engineering College, Surampalem, Andhra Pradesh
B N Jagadesh is Head of the Department of Computer Science and Engineering, Srinivasa Institute of Engineering and Technology, Amalapuram, Andhra Pradesh
Preface
Introduction 1.1 Introduction to Computer Systems Generations of computers | Applications of computers | Classification of computers 1.2 Computer Hardware Input/ Output devices | CPU | Memory 1.3 Computer Software System software | Application software 1.4 Programming Languages Machine-level programming language | Assembly-level programming language | High-level programming language 1.5 Algorithmic Problem Solving Algorithms | Characteristics of algorithm | Advantages and disadvantages of algorithm | Algorithm notation | Building blocks of algorithms | Steps for developing algorithms | Simple strategies for developing algorithms | Find minimum in a list | Insert a card in a list of sorted cards | Guess an integer number in a range | Towers of Hanoi algorithm 1.6 Building Blocks of Program 1.7 Background of Learning to Write Programs 1.8 Sample Algorithms Glossary | Summary | Multiple Choice Questions | Fill in the Blanks |State True/False | Find the Output | Find the Error | Long Answer Questions |Short Answer Questions | Exercise Algorithms | Answers
2. Fundamentals of Python Programming 2.1 Introduction to Python 2.2 Features of Python 2.3 Applications of Python Web and internet development | Scientific and numeric | Education | Desktop GUIs | Software development 2.4 Installation of Python Windows operating system | Linux operating system 2.5 Sample Program 2.6 Python Virtual Machine 2.7 Frozen Binaries 2.8 Memory Management in Python 2.9 Comparison Between C and Python 2.10 Comparison Between Java and Python 2.11 Python vs Similar Tools 2.12 Python Keywords 2.13 Python Identifiers 2.14 Python Statements 2.15 Python Indentation 2.16 Comments in Python 2.17 Differences Between Python 2.x and 3.x 2.18 Coding Styles in Python Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Long Answer Questions | Short Answer Questions | Answers
3. Syntax and Styles 3.1 Data Types 3.2 Literal 3.3 Numeric Literal 3.4 Boolean Literal 3.5 String Literal 3.6 Variable 3.7 Operators and Expressions Arithmetic operators | Comparison (relational) operators | Assignment operators | Logical operators| Bitwise operators | Membership operators | Identity operators 3.8 Expressions and Order of Evaluations 3.9 Numbers Integers | Floating point numbers | Complex numbers 3.10 Functions Applicable to All Types of Numbers 3.11 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions| Short Answer Questions | Exercise Programs | Answers
4. Control Flow 4.1 If Statement 4.2 While Statement 4.3 For Statement 4.4 Break Statement 4.5 Continue Statement 4.6 Pass Statement 4.7 Entry Controlled Loop 4.8 Exit Controlled Loop 4.9 Counter Controlled Loop 4.10 Condition Controlled Loop 4.11 Nested Loops 4.12 Sample Programs 4.13 Case Studies Simple temperature converter | Simple number system converter | Generation of vowel alphabet pattern Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output |Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers
5. Sequences–Lists 5.1 Arrays 5.2 Sequences 5.3 Using Lists 5.4 List Assignment and Equivalence 5.5 List Bounds 5.6 List Slicing 5.7 List Cloning 5.8 Nested Lists 5.9 List Comprehensions 5.10 Lists and Functions 5.11 Prime Generation with a List 5.12 Adding List Elements 5.13 Mutability 5.14 List Unpacking 5.15 Stack 5.16 Queue 5.17 Functional Programming 5.18 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks |State True/False | Find the Output |Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers 6. Tuples 6.1 Need of Tuple 6.2 Sequence Unpacking 6.3 Methods 6.4 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers 7. Dictionaries 7.1 Making a Dictionary 7.2 Basic Operations 7.3 Dictionary Operations 7.4 Sets 7.5 Iterators and Generators 7.6 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs| Answers 8. Functions 8.1 Introduction 8.2 Defining Functions 8.3 Calling Functions 8.4 Passing Arguments 8.5 Keyword Arguments 8.6 Default Arguments 8.7 Required Arguments 8.8 Variable-length Arguments 8.9 Return Statement 8.10 Nesting of Passing Arguments 8.11 Anonymous Functions 8.12 Recursive Function 8.13 Scope of Local and Global Variable 8.14 Documentation Strings 8.15 Sample Programs 8.16 Case Studies Recursive binary search | Substitution Cipher| Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs| Answers
9. Modules 9.1 Introduction 9.2 Importing Modules Importing all elements of a module | Importing the specific elements of a module 9.3 Creating Modules 9.4 Use of name 9.5 Name Spacing Scope 9.6 Reloading Module 9.7 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers 10. Object Oriented Programming Principles 10.1 Class Statement 10.2 Class Body 10.3 Objects 10.4 Class Methods 10.5 Self Variable 10.6 Class Properties and Instance Properties 10.7 Static Method 10.8 Data Hiding 10.9 Deleting an Object 10.10 Constructor 10.11 Method Overriding 10.12 Inheritance 10.13 Composition or Containership or Complex Object 10.14 Abstract Classes and Interfaces 10.15 Metaclass 10.16 Operator Overloading Reverse adding | getitem() and setitem() | Membership operators | Miscellaneous functions 10.17 Garbage Collection 10.18 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs| Answers 11. Packages 11.1 Introduction to PIP 11.2 Installing Packages via PIP 11.3 Using Python Packages 11.4 Absolute and Relative Imports 11.5 Namespace Package 11.6 Sample Programs Glossary |Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers 12. Strings and Regular Expressions 12.1 Methods of String Objects Escape sequencing 12.2 Iterating Strings 12.3 String Module 12.4 String Formatting 12.5 Regular Expression Re-module 12.6 Dictionary-based Formatting Expressions 12.7 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers 13. Files and Directory Access 13.1 Files and Streams 13.2 Opening a File The read mode | The write mode | The append mode 13.3 Reading/Writing Operations on a File The read operation | The write operation 13.4 Other File Operations 13.5 Iterating through Files 13.6 Splitting Words 13.7 Serialization and De-serialization 13.8 Hash Files 13.9 Directory Access 13.10 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers 14. Errors and Exceptions 14.1 Motivation 14.2 Examples of Exception 14.3 Handling Exceptions 14.4 Try Keyword 14.5 Finally Keyword 14.6 Handling Exception in Invoked Functions 14.7 With and Except Statements 14.8 Raising Exceptions 14.9 Re-raising Exception 14.10 Instantiating Exception 14.11 Custom Exceptions 14.12 Assert Statement 14.13 Pre-defined Clean-up Actions 14.14 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs| Answers
15. Multithreading 15.1 Introduction to Thread 15.2 Differences Between Process and Thread 15.3 Threading Module 15.4 Thread Synchronization 15.5 Sample Program Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers
16. Tkinter 16.1 Introduction 16.2 Widget 16.3 Label Widget 16.4 Button Widget 16.5 Checkbutton Widget 16.6 Entry Widget 16.7 Listbox Widget 16.8 Radiobutton Widget 16.9 Scrollbar Widget 16.10 Text Widget 16.11 Container Widgets 16.12 Frame Widget 16.13 Menu Widget 16.14 Labelframe Widget 16.15 Message Widget 16.16 Combobox Widget 16.17 Scale Widget 16.18 Canvas Widget 16.19 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers
17. Events 17.1 Event Object 17.2 Binding Callbacks to Events 17.3 Events Names 17.4 Keyboard Events 17.5 Mouse Events 17.6 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers
18. Standard Library 18.1 Operating System Interface 18.2 Text Processing 18.3 Mathematics 18.4 Internet Access 18.5 Dates and Times 18.6 Data Compression 18.7 Turtle Graphics 18.9 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers
19. Testing 19.1 Basic Concepts of Testing 19.2 Unit Testing in Python 19.3 Grouping Test Cases in Unit Testing 19.4 Loading and Running Tests 19.5 Sample Programs Glossary | Summary | Multiple Choice Questions | Fill in the Blanks | State True/False | Find the Output | Find the Error | Long Answer Questions | Short Answer Questions | Exercise Programs | Answers
Appendix A: Networking Appendix B: Sending E-mail Appendix C: Plotting Graphs Appendix D: CGI/Web Programming using Python Index