1. Preface
1. Who this book is for
2. What this book covers
3. To get the most out of this book
4. Get in touch
1. A Gentle Introduction to Python
1. A proper introduction
2. Enter the Python
3. About Python
1. Portability
2. Coherence
3. Developer productivity
4. An extensive library
5. Software quality
6. Software integration
7. Satisfaction and enjoyment
4. What are the drawbacks?
5. Who is using Python today?
6. Setting up the environment
1. Python 2 versus Python 3
7. Installing Python
1. Setting up the Python interpreter
2. About virtual environments
3. Your first virtual environment
4. Installing third-party libraries
5. Your friend, the console
8. How to run a Python program
1. Running Python scripts
2. Running the Python interactive shell
3. Running Python as a service
4. Running Python as a GUI application
9. How is Python code organized?
1. How do we use modules and packages?
10. Python's execution model
1. Names and namespaces
2. Scopes
3. Objects and classes
11. Guidelines for writing good code
12. Python culture
13. A note on IDEs
14. Summary
2. Built-In Data Types
1. Everything is an object
, 2. Mutable or immutable? That is the question
3. Numbers
1. Integers
2. Booleans
3. Real numbers
4. Complex numbers
5. Fractions and decimals
4. Immutable sequences
1. Strings and bytes
1. Encoding and decoding strings
2. Indexing and slicing strings
3. String formatting
2. Tuples
5. Mutable sequences
1. Lists
2. Bytearrays
6. Set types
7. Mapping types: dictionaries
8. Data types
1. Dates and times
1. The standard library
2. Third-party libraries
2. The collections module
1. namedtuple
2. defaultdict
3. ChainMap
3. Enums
9. Final considerations
1. Small value caching
2. How to choose data structures
3. About indexing and slicing
4. About names
10. Summary
3. Conditionals and Iteration
1. Conditional programming
1. A specialized else: elif
2. The ternary operator
2. Looping
1. The for loop
1. Iterating over a range
2. Iterating over a sequence
2. Iterators and iterables
3. Iterating over multiple sequences
4. The while loop
5. The break and continue statements
6. A special else clause
, 3. Assignment expressions
1. Statements and expressions
2. Using the walrus operator
3. A word of warning
4. Putting all this together
1. A prime generator
2. Applying discounts
5. A quick peek at the itertools module
1. Infinite iterators
2. Iterators terminating on the shortest input sequence
3. Combinatoric generators
6. Summary
4. Functions, the Building Blocks of Code
1. Why use functions?
1. Reducing code duplication
2. Splitting a complex task
3. Hiding implementation details
4. Improving readability
5. Improving traceability
2. Scopes and name resolution
1. The global and nonlocal statements
3. Input parameters
1. Argument-passing
2. Assignment to parameter names
3. Changing a mutable object
4. Passing arguments
1. Positional arguments
2. Keyword arguments
3. Iterable unpacking
4. Dictionary unpacking
5. Combining argument types
5. Defining parameters
1. Optional parameters
2. Variable positional parameters
3. Variable keyword parameters
4. Positional-only parameters
5. Keyword-only parameters
6. Combining input parameters
7. More signature examples
8. Avoid the trap! Mutable defaults
4. Return values
1. Returning multiple values
5. A few useful tips
6. Recursive functions
7. Anonymous functions
8. Function attributes