Python is a simple yet powerful programming language that is widely used in data analysis, big data, web crawlers, automated operation and maintenance, scientific computing, and artificial intelligence. Python is also becoming more and more important. It has become a subject in the National Computer Rank Examination, and some primary and secondary schools have also opened Python programming courses. This book adheres to the concept of being interesting, informative, fun and easy to use. It simplifies complex Python technical problems through the relaxed dialogues, funny images and exaggerated actions of three cartoon characters. This book has a total of 16 chapters: Chapter 1 introduces the history and characteristics of Python and sets up the development environment. Chapters 2 to 5 introduce the basic knowledge of Python, including data types, expressions, process control, etc. Chapters 6 and 7 introduce Python's commonly used container type data and string data. Chapters 8 to 11 introduce advanced Python content, including functions, classes and objects, exception handling, and commonly used built-in modules. Chapters 2 to 16 introduce how to use Python's utility libraries, including file reading and writing, graphical user interfaces, network communications, database access, and multithreading. This book has a "hands-on" session in each chapter, where you can find application examples; and a "practice" session at the end of each chapter, where you can find synchronized exercises. If you want to get started with Python, whether you are an elementary school student who wants to learn programming, a middle school student who wants to participate in computer competitions, a college student majoring in computer-related subjects, or even a working person engaged in software development, this book is suitable for you to read and learn. Chapter The tank is full! Ready to go! 1.1 History of Python 1.2 Features of Python 1.3 Setting up Python development environment 1.4 Want to get some help? Write and run a Hello World program 1.4.1 Interaction 1.4.2 File Mode 1.5 Practice
Chapter 2: Programming Basics 2.1 Identifiers 2.2 Keywords 2.3 Variables 2.4 Statements 2.5 Code Comments 2.6 Modules 2.7 Get started - access code elements between two modules 2.8 Practice Chapter 3 Numerical Data 3.1 Data types in Python 3.2 Integer Types 3.3 Floating-point types 3.4 Complex Types 3.5 Boolean Type 3.6 Conversion between digital types 3.6.1 Implicit type conversion 3.6.2 Explicit Type Conversion 3.7 Practice Chapter 4 Operators 4.1 Arithmetic operators 4.2 Comparison Operators 4.3 Logical Operators 4.4 Bitwise Operators 4.5 Assignment Operators 4.6 Operator Precedence 4.7 Practice Chapter 5 Program Flow Control 5.1 Branch Statements 5.1.1 if structure 5.1.2 if-else structure 5.1.3 if-elif-else structure 5.2 Loop Statements 5.2.1 while statement 5.2.2 for Statement 5.3 Jump Statement 5.3.1 break Statement 5.3.2 continue Statement 5.4 Get your hands dirty - count the number of daffodils 5.5 Practice Chapter 6 Container Types of Data 6.1 Sequence 6.1.1 Sequence Indexing Operations 6.1.2 Addition and multiplication operations 6.1.3 Slice Operation 6.1.4 Membership Test 6.2 Lists 6.2.1 Create a list 6.2.2 Appending Elements 6.2.3 Inserting Elements 6.2.4 Replacement Elements 6.2.5 Deleting Elements 6.3 Tuples 6.3.1 Creating Tuples 6.3.2 Tuple Unpacking 6.4 Collections 6.4.1 Creating a Collection 6.4.2 Modifying a Collection 6.5 Dictionary 6.5.1 Creating a dictionary 6.5.2 Modifying the dictionary 6.5.3 Accessing Dictionary Views 6.6 Get started - traversing the dictionary 6.7 Practice Chapter 7 Strings 7.1 String Representation 7.1.1 Ordinary Strings 7.1.2 Raw Strings 7.1.3 Long Strings 7.2 Conversion between strings and numbers 7.2.1 Converting Strings to Numbers 7.2.2 Converting Numbers to Strings 7.3 Formatting Strings 7.3.1 Using placeholders 7.3.2 Format Control Characters 7.4 Manipulating Strings 7.4.1 String Search 7.4.2 String Replacement 7.4.3 String Segmentation 7.5 Get started - Count the frequency of words in English articles 7.6 Practice Chapter 8 Functions 8.1 Defining functions 8.2 Calling a function 8.2.1 Calling functions with positional arguments 8.2.2 Calling functions with keyword arguments 8.3 Default Values of Parameters 8.4 Variable Parameters 8.4.1 Tuple-based Variable Parameters (*Variable Parameters) 8.4.2 Dictionary-based variable parameters (**variable parameters) 8.5 Scope of variables in functions 8.6 Function Types 8.6.1 Understanding function types 8.6.2 Filter() 8.6.3 Mapping function map() 8.7 lambda() function 8.8 Get your hands dirty – using more lambda() functions 8.9 Practice Chapter 9 Classes and Objects 9.1 Object-Oriented 9.2 Defining Classes 9.3 Creating Objects 9.4 Class Members 9.4.1 Instance variables 9.4.2 Construction method 9.4.3 Instance Methods 9.4.4 Class variables 9.4.5 Class Methods 9.5 Encapsulation 9.5.1 Private variables 9.5.2 Private Methods 9.5.3 Using Attributes 9.6 Inheritance 9.6.1 Inheritance in Python 9.6.2 Multiple inheritance 9.6.3 Method Overriding 9.7 Polymorphism 9.7.1 Inheritance and Polymorphism 9.7.2 Duck Typing and Polymorphism 9.8 Practice Chapter 0 Exception Handling 10.1 Exceptions - Division by Zero 10.2 Catching Exceptions 10.2.1 try-except Statement 10.2.2 Multiple except code blocks 10.2.3 Multiple exception capture 10.2.4 Nested try-except Statements 10.3 Using finally blocks to release resources 10.4 Custom Exception Classes 10.5 Get your hands dirty - manually raise an exception 10.6 Practice Chapter 1 Commonly used built-in modules 11.1 Mathematical calculation module - math 11.2 Date and time module - datetime 11.2.1 The datetime class 11.2.2 Date Class 11.2.3 The time class 11.2.4 Calculating time span class - timedelta 11.2.5 Converting Date and Time to and from Strings 11.3 Regular Expression Module -- re 11.3.1 String Matching 11.3.2 String Search 11.3.3 String Replacement 11.3.4 String Segmentation 11.4 Tips - How to use official documents to find module help information 11.5 Practice Chapter 2 File Reading and Writing 12.1 Opening Files 12.2 Closing a File 12.2.1 Closing files in a finally block 12.2.2 Closing a File in a with as Block 12.3 Reading and Writing Text Files 12.4 Hands-on - Copying text files 12.5 Reading and Writing Binary Files 12.6 Getting Started - Copying Binary Files 12.7 Practice Chapter 3 Graphical User Interface 13.1 Graphical User Interface Development Libraries in Python 13.2 Installing wxPython 13.3 wxPython Programs 13.4 Custom Window Class 13.5 Adding Controls to a Window 13.6 Event Handling 13.7 Layout Management 13.7.1 Box Layout Manager 13.7.2 Hands-on - Refactoring event handling examples 13.7.3 Hands-on - Box Layout Manager Nesting Example 13.8 Controls 13.8.1 Text Input Control 13.8.2 Checkboxes and Radio Buttons 13.8.3 Lists 13.8.4 Static Image Control 13.9 Tips and Tricks - How to use wxPython official documentation 13.10 Practice Chapter 4 Network Communication 14.1 Basic Network Knowledge 14.1.1 TCP/IP 14.1.2 IP Address 14.1.3 Ports 14.1.4 HTTP/HTTPS 14.2 Build your own web server 14.3 The urllib.request module 14.3.1 Sending a GET request 14.3.2 Sending a POST Request 14.4 JSON Data 14.4.1 Structure of a JSON Document 14.4.2 Decoding JSON Data 14.5 Get started - downloading image examples 14.6 Move your hands - return all memo information 14.7 Practice Chapter 5 Accessing the Database 15.1 SQLite Database 15.1.1 SQLite Data Types 15.1.2 Mapping Python Data Types to SQLite Data Types 15.1.3 Using GUI Management Tools to Manage SQLite Databases 15.2 Basic Operation Process of Database Programming 15.3 sqlite3 Module API 15.3.1 Database Connection Object 15.3.2 Cursor Object 15.4 Get started - Database CRUD operation examples 15.4.1 Data Table in Example 15.4.2 Unconditional Query 15.4.3 Conditional Query 15.4.4 Inserting Data 15.4.5 Update Data 15.4.6 Deleting Data 15.5 Tips - Preventing SQL Injection Attacks 15.6 Practice Chapter 6 Multithreading 16.1 Thread-related knowledge 16.1.1 Process 16.1.2 Threads 16.1.3 Main Thread 16.2 Threading Module -- threading 16.3 Creating a Child Thread 16.3.1 Custom Function to Implement Thread Body 16.3.2 Customizing the thread class to implement the thread body 16.4 Thread Management 16.4.1 Waiting for a Thread to End 16.4.2 Thread Stop 16.5 Get started - downloading image examples 16.6 Practice |