Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Which book would you recommend for learning Python in detail?
174 points by jacoberr on Jan 29, 2023 | hide | past | favorite | 60 comments
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.


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


Fluent python is great but I don’t recommend you start with Fluent Python, it’s for people who already know python and want to go that extra mile. I still use it as a reference almost every month.

Automate the boring stuff is a good beginner book, I like the coverage in “Introducing Python” by Lubanovic because it covers Modules and Packages for a whole chapter whereas in other books distributing your code is often a footnote. Even Fluent Python (my favorite python book) doesn’t have that great coverage of that.


Personally I found Fluent Python to be one of the best books I’ve read for learning a new programming language. I had slight Python familiarity before and over ten years of professional experience writing code. I was coming into a new job as an engineering manager managing a team of experienced Python developers and had to get up to speed very quickly so I spent a few weeks doing the Python track in Exercism while simultaneously reading Fluent Python and I was able to get to the point where I felt confident reviewing my reports’ code and giving worthwhile feedback.


If you consider yourself a good programmer, read the official reference documentation. A good book was Essential Reference by Beazley but I don't think it was updated for Python3 yet. [edit: http://www.dabeaz.com/python-distilled/ is the Python3 version]

Also perhaps Python Cookbook.

A major part of any language is knowing the standard library(-ies).


Nice list. I'd add

* Practices of the Python Pro (https://www.manning.com/books/practices-of-the-python-pro) — learn to design professional-level, clean, easily maintainable software at scale, includes examples for software development best practices

* Intuitive Python (https://pragprog.com/titles/dmpython/intuitive-python/) — productive development for projects that last


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.


These seem to be too deep in the internals for most Python programmers.

OK, __slots__ and pdb, but the rest are "as needed" and don't have much to do with everyday Python programming.


Honestly, I can't answer any of these fluently. What would you suggest me to do?


Apologies jacoberr, i think i've misunderstood what you were asking for originally:

> I feel like python is made on the simple basic structure and I don't know that ...<snip>... I feel like I really don't know the internals of python

I think i took what you said a bit too literally :-) You definitely don't need this stuff to be a solid, competent Python developer.

I was suggesting these topics because i feel like understanding these were what unlocked the ability for me to handle new things - things new to me, not necessarily new to python - and be able to intuit what they meant or were doing behind the scenes. This knowledge made it so that i stopped feeling like "i don't know exactly how that works" when i saw new things in Python.

Don't get me wrong, it's not magic. E.g. when the walrus operator was introduced, i could guess how this was done but i didn't know just by looking at it.


I think this is a challenge for you, to figure out the answer to the questions. You will need to google some things and do some experimentation with complex Python code, but when you figure out the answers you will know quite a bit about the internals of Python.


That was my reaction too ! Most of this is not useful at all for a day to day job.

But then I re-read the OP question, and he asks indeed about learning Python 'in detail' - what's going on under the hood.

Then I spend some time researching those questions, and it's pretty interesting !


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.


There is one book about the CPython internals: https://realpython.com/products/cpython-internals-book/.

You can also explore the CPython dev guides: https://devguide.python.org/internals/.


On the one hand, it's great to know what's happening (deep) under the hood and this probably makes for very interesting reading.

On the other hand, if you want to be a productive Python programmer, don't feel like you need to know anything about C++ to do so. there may eventually come a time where it becomes relevant for you, but you can get very far before it comes up.


great stuff, thanks so much! ! I've been looking for python internals resources.


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.


I went through and still go through many other Python resources like blogs, videos, etc. But never another book or any MOOC on Python.

And reading and working with large codebases is very important for practical work. And it has no substitution.

I will recommend this path:

Read and do all exercises from Python Crash Course ---> Solve coding problems from Codewars. Choose Codeforces or Project Euler as well, if you have the corresponding bend ---> Make your own projects, solve your own problems ---> Contribute to Open Source projects --> Get hired. Unique growth happens after using a language in job. Or use Python in your job

In the intermediate space somewhere, learn something where you can use Python. It may be webdev, gamedev, cybersecurity, or ML/AI. Using Python is the key here.

Different people want different things when they want to learn a language. So, choose based on your goals.


It is good book if you are just starting. It is also good book if you do not have prior programming experience with other programming languages. But if you want to get more deep understanding of Python you need to read after other books that are mentioned in this ASK HN thread.


Its easy to miss, but the Third Edition just came out Jan 2023.


Where did you learn to write in this style?


Is it any good?

It mainly started in Humanities classes in middle school. I had great History/Geography/Bengali teachers there.

The gist of what they taught me was to optimize writing for one thing and one thing only- clear communication of information. No need to impress or bloat. So that the person grading your test copy finds it the most convenient to read your answer (hence bullet points, smaller paragraphs, etc.), and finds the answer so easily, that they don't dare to deduct marks. India is big on standardized tests, and a total stranger grades your copy.

I used to optimize for grades, and now I do for communication of information. I employ the same things when writing tutorials, documentations, and reports.

I am a reader, and some advices from one/two memoirs of authors I read stuck with me.

I also used to spend 10-20 hours per week on Quora during college, and was in the eyes of admins there, and worked on all sorts of pilot projects. I also had real recognition and multiple thousand followers in one non-English language version of Quora. Practice comes handy.

I also think communication is very important- in teaching, presenting, and writing. So writing is only a part of a bigger part of myself. And communication not in the smelly MBA/LinkedIn kind of way. Communication in its true sense.

I also think that I shouldn’t try to impress or flex while writing. I can comfortably do that because I have plenty other ways to wow people in life. So no word or sentence I use is engineered to impress anyone.

And I always keep in mind that I am selling something. (I have no ties to the publisher or the author of the book here) I really benefited from the book, so I spread the word whenever I can. So, if I can convice 10 people to buy/borrow, and 2 of them read it in full, I honestly believe that they will benefit.

I don't think I am a particularly good writer. However, if you find it good, this is how I do it.


Looks like Facebook advertising meets Ultima Online chat.


Being toxic is not an admirable trait.


Sure. Relevance?


Is it any good?

No. It's bloody awful.


Why is it "bloody awful"?


LinkedIn would be my guess...


Bullseye.


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.


I guess it depends on people. Books have been very useful companions for me over two decades. They help clarify and fill gaps in my knowledge. Hands-on experience comes first but books are a useful addition.


I learned to program in my early teen years from books I checked out from the library, but since then didn't read a single programming book.

Recently, I needed to ramp up quickly on an embedded C project (without any past MCU programming experience), and turned to a book for the first time in ~15 years. It was a refreshing experience - it was a short book, and I read it cover to cover over a weekend, but it really enabled me to be successful in the project I had to take on.

I like to think of real-world experience as building a sponge: you fill in the areas that you need to as you go, creating a sparse structure of knowledge. This complements formal training (whether a book or a class) - I think of these more "complete" approaches as pouring water into the sponge. Having hands-on experience lets you take more advantage of a class or book, and the class or book fills in the gaps that you simply didn't have to learn as you built things.


For some people, I assume it's effective, it's never been that way for me. I learned Python by writing Python code and reading the official Python docs and supplementing those docs with random blog posts and other Python sites. Folks who don't already have a number of programming languages under their belt may benefit more from a book perhaps.


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.


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


While I’d likely recommend a book over YouTube playlists, I also got a lot of value from the YouTube channel of the guy that wrote pre-commit (anthonywritescode). He does everything from explaining the basics all the way up to debugging Cpython internals. It’s a great find since the majority of coding channels tend to be beginner focused.


I also enjoyed watching Anthony's videos, a lot of them are short and focused on a specific subject. I stumbled upon his channel when I was struggling with some challenging type hinting issues, and ended up binge watching hours of his content.


+1 for Anthony's content. He even has a repository on github [1] with links to all of his videos for easier searching, and they're all labeled with a difficulty level. It's currently up to 520 videos!

[1] https://github.com/anthonywritescode/explains


* 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


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.



Welcome to HN Hermann12.


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...


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.



Surprised no one else mentioned this. The official documentation includes a tutorial that is quite good. I would read it before jumping into Fluent Python. https://docs.python.org/3/tutorial/index.html In addition, you can download the docs as a PDF. Several years ago, I printed the tutorial so I could sit on the couch and read through it, which was a much better situation than having to do it on a screen of any type. https://docs.python.org/3/download.html I really wish all docs would have a PDF option.


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.


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.


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...


This guy is one of the reasons that held back Python 3 adoption. I remember starting with his tutorials around 2017 which were adamant that begginers should not learn Python 3 while at the time his course was the hottest one and was massively promoted on reddit for example. He was also publishing articles like this [0].

It's great that people like him are spending a lot of time helping others learn but imo he has done more harm than good.

[0] https://learnpythonthehardway.org/book/nopython3.html


> This guy is one of the reasons that held back Python 3 adoption.

That seems like an extraordinary amount of influence to ascribe to one guy who wrote a textbook. Python 3 adoption was mostly driven by large projects. I can't think of any sizable Python project that would base their decision to migrate on what some introductory CS students are learning.


I second this. The exercise style has been effective and i use this as a textbook for all the students i coach.


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.


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.


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.


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!


https://futurecoder.io

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


Watch almost anything on YouTube by James Powell

http://www.dontusethiscode.com/


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.


OP thinks her education is lacking, and wants to deep dive in a language she already uses.


Thank you everyone for your detailed suggestion.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: