Cover....1
Half Title....2
Series Page....3
Title Page....4
Copyright Page....5
Contents....6
About the Editor....14
Chapter 1: Introduction to Python....16
PYTHON 2 VS. PYTHON 3....18
A BRIEF HISTORY OF PYTHON....26
INSTALLING AND CONFIGURING PYTHON....31
HOW TO INSTALL PYTHON ON WINDOWS....34
How to Install from the Microsoft Store....37
How to Install from the Full Installer....39
HOW TO INSTALL PYTHON ON macOS....40
How to Install from the Official Installer....43
How to Install from Homebrew....44
HOW TO INSTALL PYTHON ON LINUX....46
How to Install on Ubuntu and Linux Mint....48
How to Install on Debian Linux....49
How to Install on openSUSE....49
How to Install on CentOS and Fedora....50
How to Install on Arch Linux....50
HOW TO BUILD PYTHON FROM SOURCE CODE....51
HOW TO INSTALL PYTHON ON iOS....54
HOW TO INSTALL PYTHON ON ANDROID....55
ONLINE PYTHON INTERPRETERS....55
REGENERATE CONFIGURE....56
Chapter 2: Python Data Type....58
Additional Methods on Integer Types....61
STRING DATA TYPE....69
SET DATA TYPE....77
Operators and Methods....77
Modifying a Set....79
NUMBERS DATA TYPE....80
Integers....82
Floating Point Numbers....82
Complex Numbers....83
Number Type Conversion....84
LIST DATA TYPE....87
Accessing Values in Lists....89
Updating Lists....89
Delete List Elements....90
Basic List Operations....91
Built-In List Functions and Methods....91
DICTIONARY DATA TYPE....92
Creating a Dictionary....93
Accessing Values in Dictionary....93
Updating Dictionary....94
Delete Dictionary Elements....94
Properties of Dictionary Keys....95
Built-in Dictionary Functions & Methods....95
Tuple Data Type....97
Accessing Values in Tuples....98
Updating Tuples....99
Delete Tuple Elements....99
Basic Tuples Operations....100
Built-in Tuple Functions....100
Chapter 3: Python Comments and Documentation....104
SINGLE LINE, INLINE, AND MULTILINE COMMENTS....106
HOW PYTHON MULTILINE COMMENT WORKS?....109
Block Comments....110
Shebang....111
PYTHON COMMENTING BEST PRACTICES....112
When Writing Code for Yourself....112
When Writing Code for Others....114
PYTHON COMMENTING WORST PRACTICES....115
HOW TO PRACTICE COMMENTING?....119
PROGRAMMATICALLY ACCESSING DOCSTRINGS....121
Single-Line Docstrings....121
Multi-line Docstrings....122
Docstring Formats....123
WRITE DOCUMENTATION VIA DOCSTRINGS....128
Paragraphs....130
Inline Markup....130
Sections....130
Meta-information Markup....131
Information Units....132
Inline Markup....137
Chapter 4: Programs, Algorithms, and Functions....148
PYTHON SCRIPTS AND MODULES....150
What’s the Python Interpreter?....150
Using the Python Command....152
Using the Script Filename....153
How to Run Python Scripts Interactively....154
How to Run Python Scripts from an IDE or a Text Editor....155
How to Run Python Scripts from a File Manager....156
Joining Two Strings....157
Format Floating Point in the String....157
Raise a Number To a Power....158
Working with Boolean Types....159
Use of If-Else Statement....160
Use of AND and OR Operators....161
Locating Modules....163
Standard Modules....163
Python Packages....164
PYTHON ALGORITHMS....166
How Do You Write Algorithms?....166
Characteristics of an Algorithm....168
Brute Force....169
Divide and Conquer....170
Tree Traversal Algorithms....170
Sorting Algorithms....172
Searching Algorithms....174
Algorithm Analysis....176
BASIC FUNCTIONS....176
DYNAMIC PROGRAMMING....180
Recursive Method....183
Top-Down Method....184
Bottom Down....184
LAMBDA FUNCTIONS....185
Syntax....189
Decorators....190
Chapter 5: Python’s Executional Model....194
NAMES AND NAMESPACES....196
SCOPES....201
Using the LEGB Rule....204
Functions: The Local Scope....206
Nested Functions: The Enclosing Scope....206
Modules: The Global Scope....206
Built-In Scope....210
MODIFYING THE BEHAVIOR OF A PYTHON SCOPE....211
The Global Statement....211
The Nonlocal Statement....212
Using Enclosing Scopes as Closures....214
Bringing Names to Scope with Import....215
Reviewing Unusual Python Scopes....216
Comprehension Variables Scope....216
Exception Variables Scope....217
Class and Instance Attributes Scope....217
Using Scope-Related Built-In Functions....219
OBJECTS AND CLASSES....223
Class Objects....225
Method Objects....227
Inheritance....228
Chapter 6: Python for Web Development....232
THE BASIC CONCEPTS AROUND WEB PROGRAMMING....235
THE DJANGO FRAMEWORK....242
Is Django Opinionated?....246
What Does Django Code Look Like?....247
Handling the Request (views.py)....249
Defining Data Models (models.py)....250
Rendering Data (HTML Templates)....251
REGULAR EXPRESSIONS....255
Regular Expression Objects....271
FLASK AND FALCON FRAMEWORKS....273
APPRAISAL....282
INDEX....292
Python definitely tops the charts when it comes to ease of use and beginner-friendly learning curve in the world of programming languages. At the same time, Python is essential when it comes to writing system scripts, processing big data, performing mathematical computations, creating web applications, and rapid prototyping.
With this Mastering edition, we have focused especially on the usage of Python for Web. This book explores Python programming fundamentals with interactive projects and introduces core coding concepts and the basics of Python-based web development. The reader should be ready to dive deep into the world of Python for web development in no time.
Since Python positions itself in web development as a back-end language, it is usually mixed with another front-end language to build a whole website. At the same time, reasons for using Python in web development are many: it is a flexible, versatile, and highly efficient programming language with dynamic typing capacity. This book helps readers to examine Python’s key back-end/front-end programming techniques and guides them through implementing them when creating professional projects. Furthermore, it also focuses on teaching readers how to solve common problems and developing web services with Python frameworks such as Django and Flask.
Mastering Python for Web has a goal more ambitious than simply teaching you the ropes – it aims to help you embrace and master problem solving, which could be viewed as the single most crucial skill for a coder. It offers you a focal point on starting as a beginner and growing into an expert by putting your newly acquired knowledge into practice. Programming is a hands-on skill, and this particular book helps you put your skills to test with easy-to-grasp tasks and examples.