I've been writing Python for 10 years and taught 100s of people.
Here is a FAQ with actionable advice ππ§΅
But everyone is different, so share your thoughts as well ππ¬ to help as many as possible!
π βHow do I start learning Python?β
Well, I think the answer to this question greatly depends on whether you have (considerable) programming experience with another language or not.
That's because βlearning Pythonβ can mean βlearn the syntax of the languageβ, but...
... it can also mean βlearn how to think like a programmerβ.
And, in my opinion, this is something very fundamental that you have to understand!
Being a programmer is also about having that programmer mindset.
Worry not, you can learn it π
So, π βHow do I start learning Python as a programming newbie?β.
I get asked this question a lot, and often people say βHow to learn Python if I want to do Xβ, and X is usually data science, or machine learning, or web development, web scraping, etc, etc.
Now, I'll be honest:
If you don't know X yet, then here is my answer:
The _very beginning_ is about the foundations of Python and of the mindset, it doesn't matter (YET!) what your final end goal is.
Other people might recommend other beginner-friendly books, that's FINE...
AS LONG AS you always write the code!
If you are reading a book, even if the book explicitly doesn't say so, always copy the code BY HAND.
Copy the code, and run it.
After you run the code, fix it.
You'll always make mistakes, that's part of the learning experience π.
After the code is working, break it!
The book is teaching you about some concept; let's suppose it's `for` loops.
And you just wrote a `for` loop.
Now, write a different one!
Change the thing you are iterating over!
Make assumptions about what you learnt, and check them by writing more examples!
This is, hands down, the one thing that will boost your learning (or hamper it, if you don't do this).
Do mini-mini-mini-projects after learning a couple of new concepts.
This is to make sure you understand how things work.
Have you learned about variables, the `print` function, the `input` function, and `if` statements?
Make a basic βrock, paper, scissorsβ game.
Learned about `while` loops?
Modify your game to allow the player to play multiple games.
Keep doing this: learn new concepts, try to come up with a mini-mini-mini-project that uses them.
When you find gaps in your knowledge, google them!
As a programmer, knowing how to google things is a crucial thing.
Googling things is NOT BAD.
It's ok to look things up, the language is too big for you to know everything by heart.
In short, if you are a complete beginner, start with this:
π pick a beginner-friendly book (e.g., one from inventwithpython.com);
π write all the code by yourself;
π break the code, play around with it; and
π keep doing mini-mini-mini-projects with what you learnt.
π βI know Python basics, how do I do X?β
Over time, you will start feeling more comfortable with the language and you will start having ideas about things you want to do.
This might be something mainstream, or just a random thing you really want to build.
Both are fine.
For me, this was a maze solver.
I remember it vividly, it was a project that took me all Summer to complete.
I wanted to solve mazes with Python, but I didn't know how to do any of it.
I just knew what I wanted to do: solve mazes.
When you get to this point, then you can start looking up tutorials that tackle the specific task you want to accomplish.
For me, I had to look up how to open images with Python.
I also had to learn an algorithm to solve mazes.
And so on and so forth.
After you are done, celebrate!
Celebrate all the small successes!
Then, write a couple of paragraphs about your project: struggles you went through, resources you consulted, what you did to overcome obstacles.
Now, after you have working code, ask for someone to have a look at it, and give pointers about possible improvements.
In short, ask for a small code review.
Ask a friend or a colleague, or someone you know.
If you can't think of anyone, or if you want even more input (more input is better!), put your code on codereview.stackexchange.com up for a review.
When you get the reviews in, leverage the comments to learn more.
Someone mentions a new function, concept, construct? Google it.
In short, if you have working knowledge of Python, here's what to do next:
π come up with something you want to build;
π look up related tutorials;
π build your project incrementally;
π try to document your own journey; and
π use code reviews to find what to learn next.
Now, π βWhat if you have solid programming experience, and just want to get started with Python?β
Whenever I need to learn a programming language's syntax, I check @tutorialspoint first.
4οΈβ£ Another suggestion is to open the Python docs, specifically on the page about the standard library (docs.python.org/3/library/indeβ¦), and start learning about a module you don't know yet.
Read up on the module and write a project using it.
So, if you want to avoid learning plateaus:
π Learn your way around the docs;
π Do `dir(obj)` on a random object;
π Go online read Q&As about Python; and
π Learn new modules;
What would you add to this list of suggestions to avoid learning plateaus?
That's it for this FAQ thread, I hope it was valuable!
Want to learn more about Python π?
If so, make sure to follow me (@mathsppblog) as I have a lot of great content in store just for you!
It would also be a HUGE help if you could retweet the first tweet of this thread, as it helps more people learn Python π:
TL;DR:
π βHow do I start learning Python as a programming newbie?β
π pick a beginner-friendly book (e.g., one from inventwithpython.com
);
π write all the code by yourself;
π break the code, play around with it; and
π keep doing mini-mini-projects with what you learnt.
π βI know Python basics, how do I do X?β
π come up with something you want to build;
π look up related tutorials;
π build your project incrementally;
π try to document your own journey; and
π use code reviews to find what to learn next.
π βWhat if you have solid programming experience, and just want to get started with Python?β
π learn the syntax (e.g., on tutorialspoint.com/python/index.hβ¦
); and
π learn the distinguishing features (e.g., with gum.co/pydonts).
π βCan I learn Python for free?β
π you can; but
π you don't have to
π βHow can I avoid learning plateaus?β
π learn your way around the docs;
π do `dir(obj)` on a random object;
π go online read Q&As about Python; and
π learn new modules;
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
Do you want to master Python π list comprehensions?
Do you want to become more proficient working with lists in Python π?
If you answered with βyesβ, then here's a cheatsheet of mine to help you out.
This is also a thread π𧡠that breaks it down and explains everything:
First off, here is the anatomy of a list comprehension.
There's 4 parts to a list comp:
1. enclosing brackets to create the list [];
2. expression that transforms your data;
3. `for` iteration over the initial data;
4. (optional!) condition to filter some data.
Do list comprehensions look confusing?
Maybe.
But that's because you didn't realise that list comprehensions have equivalent `for` loops!
The coloured boxes below show the equivalent bits in the list comp and in the `for` loop:
If you type `import this` in a Python REPL, you will be presented with the Zen of Python, a document with some guidelines that you can follow when writing code.