HACKER Q&A
📣 jacoberr

Which book would you recommend for learning Python in detail?


Hi, I know some programming. I know C and some python as well. I have built projects with python but every time I work with python, I feel like python is made on the simple basic structure and I don't know that. I find myself constantly looking for small things as well, I feel like I really don't know the internals of pythons. Which book would you recommend that you go beyond the syntax and shows how things works on a basic level so that I can get build up some intuition while working with python. Forgive me if I failed to express myself.


  👤 guiambros Accepted Answer ✓
Fluent Python [1] is a great book, very comprehensive, yet it goes deeper than just the basics. Python Distilled [2] is another option. Or if you prefer more project-oriented learning style, Automate the Boring Stuff with Python [3] is probably a better fit.

When you're ready to go beyond the basics, I recommend Effective Python [4] and Serious Python [5]. Both go deeper on classes, metaclasses, how objects are represented internally, and Serious Python covers a bit of functional programming, scaling, etc.

[1] https://www.fluentpython.com/

[2] http://www.dabeaz.com/python-distilled/

[3] https://automatetheboringstuff.com/

[4] https://effectivepython.com/

[5] https://nostarch.com/seriouspython


👤 CraigJPerry
I wouldn’t recommend a book, instead i’d give you a couple of challenges, each of these is <1-2 hours in isolation:

    1. Explain to me like i’m 5,  what exactly __slots__ is for? Write me some demo code to illustrate - the reason i’d set this challenge is because you’d come out the other side knowing how objects work and how it’s more or less dicts all the way down (to be clear, slots is an exception to the dicts all the way down view which is why i think its a good example to get stuck into)
    2. Write me some demo code that explains the purpose of locals()
    3. Teach me how to use dis.dis(), explain to me what each possible opcode means
    4. Explain to me how to use pdb, include conveniences like breakpoint() in your explanation
    5. Show me 3x working examples of calling a c function from python. Explain the different approaches you took
If you can nail these 5 questions, I’d feel pretty confident betting on you knowing enough python to be able to take on something really advanced like modifying the supported grammar of jinja for example.

👤 f311a
If you want to go really deep, I would recommend reading some blogs about Python internals:

https://tenthousandmeters.com/tag/cpython/

https://rushter.com/blog/tags/cpython/

https://eli.thegreenplace.net/tag/python-internals

https://realpython.com/cpython-source-code-guide/

I'm not aware of any good books about Python's internals.


👤 __rito__
Python Crash Course by Eric Matthes.

I am a Deep Learning Research Engineer who works 100% in Python.

I had just started second year in college with only basic knowledge in imperative C. Didn't even know how to write a C function other than main().

Then I started learning Python with Python Crash Course by Eric Matthes.

I finished the entire book in five days. I really enjoyed it and learned a lot.

This is the ONLY programming book I read cover-to-cover, and the only Python book I have ever read.

This book served me greatly.

When anyone asks for Python book recommendation, I recommend this book only.

You don't need any other.

This book has the basics taught, then goes through three projects. One of them is a game. I remember.

All the exercises are great, self-contained, doable without outside help, and help you grow.

And the book's design has all that No Starch Press goodness to it.

Go for it.


👤 dfee
Is learning a language by book effective? Despite my efforts over the last ~25y, the only way I’ve learned is actually building crap software, and tuning it with learnings from language-specific frameworks and API docs.

The books just collect dust - and yet, every few years I try this experiment again with the same result.

Kinda interesting aside: I’ve been told I write great code in a particular language, while eschewing near universal patterns - patterns I’d probably have picked up if I’d gotten to Chapter 3 of any of these books. (It’s hard to independently discover cargo cult habits).

My take on the question: no book necessary.


👤 rmk
I have a recommendation that goes against 'learn the language constructs by reading a book about them'. I recommend Python Module of The Week.

https://pymotw.com/3

The advantage of this is that you learn by looking at examples, and at the same time you learn the standard library. In my opinion it's much more valuable to learn the standard library of a language once you know a little bit of the language itself, because it helps you write useful programs and learn the language in that way.


👤 saboot
It's from 2015, but I learned a lot from watching Philip Guo's playlist on python internals

https://www.youtube.com/playlist?list=PLV7iu6GiDKwQWZbapY5mP...

Like you I want to know more about CPython behind the scenes, not how to use Python itself. I like the deeper understanding


👤 bckr
* Effective Python

This teaches 90 specific ways to be more Pythonic

* Robust Python

This teaches some architectural / implementation patterns for code bases larger than a script

* High Performance Python

How to get the most juice out of Python, including compiling


👤 Hermann12
Hi, I learned FORTRAN on University. After that I don’t programming, but as an engineer I searched some solutions for automatisation. So I have to learned programming again, because FORTRAN can’t solve my requirement.

Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming, by Eric Matthes is my favourite for self study the basics.


👤 jphoward
James Powell frequently gives very deep Python talks at conferences like Pydata, and shows you his coding approach in real time on Vim. Plenty of them are on YouTube and are worth a watch. This one [1] entitled "So you want to be a Python expert?" has almost half a million views!

[1] https://www.youtube.com/watch?v=cKPlPJyQrt4&ab_channel=PyDat...


👤 __mharrison__
I wrote Illustrated Guide to Python 3 to fill in knowledge gaps that I kept coming across while training folks.

It is so easy to go to SO and copy and paste code and not know what is really going on. I think understanding Python at a deeper level will be even more important now that chatGPT will spit out the code for you and happily lie about some things.


👤 lancepioch

👤 yawpitch
The official docs should never be overlooked, as there’s an enormous amount to learn from The Tutorial (https://docs.python.org/3/tutorial/index.html#tutorial-index), the Standard Library (https://docs.python.org/3/library/index.html#library-index) and the Reference Manual (https://docs.python.org/3/reference/index.html).

All three are quite well written, kept more reliably up to date than any other resource, and provide links to a wealth of other material.

A particularly useful point is the link to the source code found at the top of most of the Standard Library pages… Python’s source code is really literate, and often the best way of understanding what’s happening “under the hood” is to actually look, rather than rely on someone else’s summary or intuition of what maybe only _was_ under the hood.


👤 pca2
It's not a book, but the Python3 Deep Dive courses by Fred Baptiste on Udemy are very good at helping to understand the internals of python: https://www.udemy.com/user/fredbaptiste/ If the courses are pricey, remember that Udemy seems to have major sales every couple of weeks, so I'm sure they will come down in price again soon.

👤 AdmiralAsshat
I used Learn Python The Hard Way[0], given that I had gone through the author's Learn C the Hard Way previously, but I gather that Mr. Shaw is something of a controversial choice.

[0] https://www.amazon.com/Learn-Python-Hard-Way-Introduction/dp...


👤 faizshah
I was the same way I always felt like I was writing Java in Python, I was able to make useful scripts in Python but I wasn’t able to actually “code” python. Then I took a class on python and finally everything just clicked (I studied some other books during the class as well).

For learning python (if you already know some programming) I always recommend “Introudcing Python” by Lubanovic it gives a coverage of all the major python features.

Once you are able to code basic python I use the book “Fluent Python” by Ramalho (I still use it to this day even as an advanced python programmer). This book has an amazing coverage of every single advanced feature in python. Anytime you’re on the job and you know you could use some fancy classes or some async stuff or maybe multi threading you can visit a chapter in this book and get up to speed on it. I probably open this book once a month just to refresh my knowledge on some particular python feature I want to use.


👤 giancarlostoro
One free resource I recommend is reading PEP-8 which is a Python style guide. It gives you standards to follow when coding which makes it easier to go back to code as you get used to it. Editors like PyCharm Community / Pro support it out of the box, on VS Code you need to install a plugin, but once you do, you're golden.

I also recommend reading the official Python documentation, especially when working on things, and looking at functions within whatever module you are using that you are not using. Over time you will discover functions / methods you had no idea were in there. I also suggest just exploring other modules you have yet to use.


👤 sitkack
http://www.dabeaz.com/python-distilled/

I would recommend compiling a debug build of Python and stepping through it while it executes your script, even if it takes you an entire day for a simple script. Python is a big dictionary sandwich. Everything is a dictionary, even dictionaries.

What does

A.b.c() do?

You do not need to know the Python internals. The semantics are good enough, but the leak through everywhere. You might enjoy using https://micropython.org/ to learn instead.


👤 bloopernova
I highly recommend you don't use a book, and instead use www.exercism.org instead.

Its lessons are free, open source, and extremely accessible. Nice and short, too.

And, once you're proficient, you can contribute back to it!


👤 aryanAr0ra
https://learncodethehardway.org/more-python-book/ You cannot go wrong with this. Get ready to implement Unix commands like cat, find, grep, and many more. This book will guide you to make a basic shell, a BASIC Interpreter, vi text editor, a command line browser and many more projects.

👤 moveax
https://futurecoder.io

It's not a book, but I loved it and it is really helpful.


👤 dp-hackernews
Watch almost anything on YouTube by James Powell

http://www.dontusethiscode.com/


👤 Jeff_Brown
I would recommend not learning any language completely or for it's own sake. Learn what you need when you need it. Most popular languages are absurdly sprawling things, designed to cover far more conditions and often to suit a far bigger variety of tastes than any single person needs.

👤 jacoberr
Thank you everyone for your detailed suggestion.