Need to build a website, analyze data, or train a machine-learning model? Python is a general-purpose, open-source language with readable syntax, a large community, and packages for each of those jobs. Its concise code also makes it useful for building prototypes. section 1.1 section 1.2
Start with core skills—processing text and structured data, controlling program flow, and handling files—before choosing domain-specific tools. Aim for Pythonic code: a solution that works and remains concise, readable, and maintainable. section 1.0 section 1.1
Check membership without searching for an index
Use `in` when the question is whether an item is present:
```python
assert ('cool' in 'Python is cool') == True
assert (8 in [1, 2, 3, 4, 5]) == False
```
The expression returns `True` or `False`. If you need the item's position instead, use a sequence's `index` method. section 4.3.1
Distinguish dynamic typing from type hints
A variable can refer to values of different types after reassignment:
```python
number = 1
print(type(number)) # <class 'int'>
number = "one"
print(type(number)) # <class 'str'>
```
Python also allows annotations such as `number: int = 3`, but a type hint does not enforce that type or make Python statically typed. section 6.3.1
Table 1.1 Overview of domain-specific Python tools (view table figure)
| Domain |
Tool |
Highlights |
| Web development |
Flask |
A micro web framework; good for building lightweight web apps; flexible extensibility for third-party functionalities |
| Web development |
Django |
A complete web framework; good for building database-driven web apps; highly scalable as an enterprise solution |
| FastAPI |
A web framework for building application programming interfaces (APIs); data validation and data conversion; automatic generation of API web interfaces |
| Streamlit |
A web framework for easy building of data-related apps; popular among data scientists and ML engineers |
| Data science |
NumPy |
Specialized for processing large, multidimensional arrays; high computational efficiency; integral to many other libraries |
| pandas |
A versatile package for processing spreadsheet-like two-dimensional data; comprehensive data manipulations |
| statsmodels |
A popular package for statistics, such as linear regression, correlation, Bayesian modeling, and survival analysis |
| Matplotlib |
An object-oriented paradigm for drawing histograms, scatter plots, pie charts, and other common figures with a variety of customizable settings |
| Seaborn |
An easy-to-use visualization library for drawing attractive graphics; high-level APIs based on Matplotlib |
| Machine learning |
Scikit-learn |
A wide range of preprocessing tools for building ML models; implementation of common ML algorithms |
| TensorFlow |
A framework with both high- and low-level APIs; Tensor board visualization tool; good for building complex neural networks |
| Keras |
High-level APIs for building neural networks; easy to use; good for building low-performance models |
| PyTorch |
A framework for building neural networks; more intuitive code styles than TensorFlow; good for building complex neural networks |
| FastAI |
High-level APIs for building neural networks on top of PyTorch; easy to use |
Browse the table to match a project area with specific Python tools, including web frameworks and data-science packages. section 1.2
Choose the language for the product, not just for familiarity. Python runs on common desktop platforms and suits many application domains, but mobile apps and hardware-facing software may be better served by other languages. section 1.2 section 1.3