6 Comments

I've recently decided to learn Python and have been working through your Python Crash Course book V2. I just finished up the chapter on classes, but before moving on I have been going back and reviewing everything carefully. So far so good. I'm enjoying myself.

I have found that I can read code and comprehend it fairly well enough after just a couple weeks, however, when I sit down to try to write something on my own I stumble all over getting the correct syntax written. I suppose I need to just knuckle down and type type type type away until the writing becomes easier.

I regret having stopped coding way back in the glory days of my youth on my C128 and Amiga... Oh well... hind sight... what ya gonna do about it...?

Expand full comment
author
Jan 19, 2023·edited Jan 19, 2023Author

Hi Tim. Your experience in sitting down to write code and then stumbling is *really* common. Nobody really remembers much syntax until they've used that syntax on a regular basis. It's an open secret among tech authors that we consult our own books every time we start a new project. For me, that's especially true when I start a new game project, visualization, or a new Django project. I don't always open the book, but I do refer back to the code I've already written so I don't have to remember or rethink everything for each new project.

I always tell people, what matters most is that you know what's possible. If you know you can accept an arbitrary number of arguments in a function definition, but you forget the syntax for doing so, you can easily look it up. That's way better than needing to accept an arbitrary number of arguments, and not knowing it's possible.

Have you seen the cheat sheets that go along with the book? They're meant to help people look up syntax when working on exercises or your own projects, without having to flip through the book: https://ehmatthes.github.io/pcc_2e/cheat_sheets/cheat_sheets/

Expand full comment

Yep - I printed of the sheets and have been using them to review. Also bought your flashcards a few weeks ago from Amazon. It's been going well and I am looking forward to seeing where I can go with Python.

Expand full comment

Hi Eric!

I'm totally new to coding (apart from a few lessons in high school 20 years ago) and I'm following along Python Crash Course V3. I've just finished the section on lists when I stumbled on this article. I gave it a go and copied the code into the editor and then tried my own version with films rather than books which was a success.

I maybe got a bit too big for my boots and tried to use .append but it didn't work. Is there a reason the loop doesn't work with .append or .pop and is there a preference for using a list like the one in the article vs a list across a single line?

Thanks :)

Expand full comment
author

Hi Ian! I'm glad you found this while reading the book. You might want to focus on the book and come back to some of these articles after working through what's covered in the book. Most of these articles tend to pick up where the book leaves off. But skimming these posts as you read is perfectly reasonable, for getting a sense of what else is going on with any given topic.

As for your specific question, part 9 of this series explains why modifying a list inside a for loop doesn't work the way people expect it to. Briefly, Python plans how to iterate over the list before starting the loop. If you change the list while the loop is running, that plan may no longer be appropriate.

https://www.mostlypython.com/p/python-lists-a-closer-look-part-9

If you have any followup questions, I'm happy to answer them in this thread, or in a comment on that post.

Expand full comment

Thank you so much for getting back to me! I shall check out the linked article just for my curiosity but continue working through the book :)

Expand full comment