Catalogs
Foreword
Chapter 1 Overview of Python 1
1.1 Python overview 1
1.2 Development environment3
1.3 Summary of this chapter 5
Chapter 2 Python language basics7
2.1 Python program composition7
2.2 Packages, modules, and functions8
2.3 Identifier and its naming rules 11
2.4 Common data types13
2.5 Operators and expressions 18
2.6 Objects and references 23
2.7 Inputs and outputs27
2.8 Summary of this chapter 31
Chapter 3 Branch structure 33
3.1 Flow charts and three structures33
3.2 Operators and precedence 37
3.3 Branch structure (single, double, multi-branch and nested)41
3.4 Summary of this chapter 47
Chapter 4 Loop structure49
4.1 The while loop and the sentinel loop 49
4.2 For statements and nested loops52
4.3 Iterable objects 56
4.4 Built-in function range56
4.5 The break statement, continue statement and else clause 58
4.6 Getting started with data science 63
4.7 Summary of this chapter 64
Chapter 5 Lists and Tuples66
5.1 Sequences66
5.2 Lists67
5.3 Tuples86
5.4 Unpacking and packing89
5.5 Summary of this chapter 91
Chapter 6 Dictionaries and Collections92
6.1 Dictionaries 926.2 Assemblies 99
6.3 Summary of this chapter 103
Chapter 7 String 104
7.1 Definition of the string 104
7.2 Escape characters and original strings 104
7.3 String formatting 105
7.4 Common operations on strings 108
7.5 Regular expressions112
7.6 Summary of this chapter116
Chapter 8 Functions 117
8.1 Define and call the function117
8.2 Passing arguments 119
8.3 Variable scopes 122
8.4 Recursive functions 124
8.5 Built-in functions and the Python standard library 126
8.6 Summary of this chapter 129
Chapter 9 Modules 131
9.1 Module Overview 131
9.2 Importing modules 132
9.3 Packages in Python 134
9.4 Referencing other modules 135
9.5 Summary of this chapter 138
Chapter 10 Object-Oriented Programming 139
10.1 Overview of object-oriented programming 139
10.2 Class definition and instantiation 141
10.3 Attributes and methods 143
10.4 Inheritance 150
10.5 Summary of this chapter 154
Chapter 11 Exception Handling and Program Debugging 155
11.1 Overview of Exceptions 155
11.2 Exception handling statements 156
11.3 Program debugging 159
11.4 Summary of this chapter 162
Chapter 12 File and Directory Operations 163
12.1 Definition of file 163
12.2 Directory Operations 164
12.3 File Op
內容試閱:
ForewordIn this era of rapid digital development, programming skills have become indispensable for science and engineering students. As a core course in China‘s science and engineering colleges and universities, Advanced Language Programming (Python) aims not only to help students master Python, a powerful programming language, but also to cultivate their mindset and skills for solving practical problems. With the continuous evolution of information technology, this course is undergoing reform, striving to emphasize the application of basic theories and practical skills to meet the demand for versatile talents in the new era.To better achieve this teaching goal, we have meticulously compiled High-Level Language Programming (Python) to enhance students’ programming literacy and provide solid theoretical support and practical guidance for their learning journey. Python, as a high-level programminglanguage featuring interpretive, interactive, and object-oriented capabilities, is well known for its clear and concise syntax, powerful standard library, and active community. However, its extensive features and flexible syntax rules can pose challenges to students with limited foundational computer knowledge. Many existing textbooks focus on a systematic introduction to the language itself, which often bogs students down in syntactic memorization, thereby hindering their learning experience and interest. This book reflects the authors‘ extensive teaching experience and deep understanding of the Python language. We adhere to the principle of‘learning by doing,’ closely integrating theoretical knowledge with practical applications. Each chapter is designed to develop programming skills, emphasizing Python basics, algorithmic concepts, and program structures to help students build a solid knowledge framework. Through a series of well-designed case studies and problem-based learning activities, students are encouraged to explore and innovate, fostering continuous progress through practice. The textbook’s features include:? Step-by-step and easy to understand: chapters are organized to progress from the simplest to the most complex concepts, ensuring that every point is fully comprehended.From an introduction to the Python language and runtime environment (Chapter 1), to basic syntax, data types, operators, and expressions (Chapter 2), and selective and recursive structures (Chapters 3 and 4), students are guided step by step through the fundamentals of programming.? Case-driven and problem-solving: Each chapter begins with a real-world problem, guiding students to think critically and apply what they have learned to find a solution.For example, when introducing lists and tuples (Chapter 5), dictionaries and sets (Chapter 6), and string manipulation (Chapter 7), specific cases are used to demonstrate how these data structures are applied in real programming.? Break down difficult concepts and go deeper step by step: Complex concepts and rules are divided across chapters to avoid overwhelming students with excessive learning pressure. For example, the creation and invocation of functions (Chapter 8), object-oriented programming (Chapter 10), and the use of standard and third-party libraries (Chapter 9) help students gradually acquire more advanced programming skills.? Focus on practice, strengthen skills: The book contains numerous example problem analyses, particularly code demonstrations in the Jupyter Notebook environment, which help improve students‘ hands-on ability and programming confidence.? Summarize and reinforce memory: Each chapter ends with a brief summary, providing a systematic overview of the chapter’s content and helping students consolidate what they have learned. For commonly used grammar rules and common programming errors, tips are provided in clear and concise language, aiming to help students consolidate their learning and avoid forgetting.? Up-to-date and resourceful: It covers the latest Python features, including the use of standard and third-party libraries, enabling students to keep up with technological trends.This book could not have been completed without the support and help of many peers, and we would like to express our sincere gratitude to all the teachers who have given us valuable advice and selfless assistance. At the same time, due to the limitations of the authors knowledge, it is inevitable that there are shortcomings in the book, and we sincerely hope that readers will provide us with valuable feedback and suggestions to help us improve our work in the future.