What's the BEST way to learn Python 🐍?

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.

I always recommend @AlSweigart's books that you can read for free at inventwithpython.com
That's what I started with.

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.

I did that for my maze solver: mathspp.com/blog/solving-m…
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.

So, if you already have the programmer's mindset, you can go to tutorialspoint.com/python/index.h…
Learn the syntax of Python 🐍 and make sure you get it by writing actual code.

Programming is not something you learn by reading.

You learn programming by writing.

Then learn about the distinguishing features of Python 🐍, e.g. through my free book: gum.co/pydonts
In short, if you need to quickstart your Python 🐍 learning,

πŸ‘‰ 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?”

Yes, you can.

There are MANY excellent free resources online.

I got Python jobs without ever paying a cent to learn Python.

Therefore, you don't NEED to pay to learn Python well.

(Of course, there are also AMAZING paid resources!)
🐍 β€œHow can I avoid learning plateaus?”

There are a couple of things you can do to make sure you always keep learning.

1️⃣ The first thing is to get accustomed to the documentation: docs.python.org/3/

Learn how to read it and navigate it.
If you β€œrun out of things to learn”, open the documentation and browse it randomly.

You will find something new to learn about quickly.

2️⃣ Another thing you can do is open the REPL and just type `dir(obj)`, where `obj` is a random Python object you come up with.
`dir` will show you a list with plenty of strings in there, and those strings are names of things related to the object you passed in.

There _ought_ to be a string there that you don't know the meaning of.

Congratulations, you found something new to learn about.
3️⃣ Another thing you can do is go online, to websites like StackOverflow or CodeReview, and read questions/answers about Python.

StackOverflow πŸ”—: stackoverflow.com
CodeReview πŸ”—: codereview.stackexchange.com
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
γ€€

Keep Current with Rodrigo πŸπŸ“

Rodrigo πŸπŸ“ Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mathsppblog

24 Sep
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:
Read 19 tweets
23 Sep
Do you know what the Python 🐍 `type` is?

But do you _really_ know what it is?

Here is a valuable thread that will give you insights into what `type` is and does.

Let's go πŸ‘‡πŸ§΅
What does `type` do?

You might say that `type` takes an object and returns the type of the argument.

Here are some examples:
Fine, so `type` is a function!

Or is it..?

Take a look at the example above.

`sum` is a built-in function and `type(sum)` returned β€œbuilt-in function or method”.

So, logically, if `type` is a (built-in) function, the type of `type` should give the same thing:
Read 14 tweets
20 Sep
Are you a master of Python 🐍 sequence slicing?

Here is a short thread 🧡 covering four idiomatic slicing patterns that you could get used to.

These four patterns are great because they have a clear interpretation of what they do.

Here we go πŸ‘‡πŸ§΅
🐍 s[n:]

If `n β‰₯ 0`, then `s[n:]` means

πŸ‘‰ β€œSkip the first `n` elements.”

⚠ If `n` is 0, then we skip 0 elements, which is another way of saying we get all of them.
That's the same as `s[:]`.
🐍 s[-n:]

If `n > 0`, then `s[-n:]` means

πŸ‘‰ β€œThe last `n` elements.”

⚠ -0 and 0 are the same, so `s[-0:]` gets all the sequence, like above.
Read 10 tweets
18 Sep
Are you as curious (and nerdy πŸ€“) as I am? πŸ€”

If you are, you are going to love what I'm about to show you 🀯

Let's build a Python 🐍 quine: a program that prints itself!

This thread walks you through the process of building the quine you can see here.

πŸ‘‡πŸ§΅
If we want a program that _prints_ itself, we need to start with a print statement:

```
print()
```

When we run this program, a single newline gets printed as output.

But we want a program that prints itself, right?

So let's try putting the program in the `print`.
For that, we try opening " inside the `print` and we start typing the program, itself, inside the string:

```
print("print()")
```

This outputs

```
print()
```

But now our program grew, so we need to keep up with it inside the string.
Read 11 tweets
17 Sep
πŸ€” Do you ever write some Python 🐍, look at it, and get the feeling there MUST be a better ✨ way to do that..?

I get that ALL the time! πŸ˜…

That's why I started researching and writing articles to help me (and you!) write better code.

Here's all 28 of them (so far!) πŸ‘‡πŸ§΅
I have also been compiling all the articles into an eBook πŸ“–, that I am "selling" for free πŸ’Έ.

Why?

I decided to make it free because that's how I learned Python: from free books and articles, available online.

Here's the link to the free book:

gum.co/pydonts
01 - Pydon't disrespect the Zen of Python

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.

It's not a religion!

Just some guidelines :)

mathspp.com/blog/pydonts/p…
Read 32 tweets
9 Sep
Have you ever had a hard time debugging 🐞 a Python 🐍 script?

If you say you haven't, you're lying! πŸ˜†

Let me show you something that you're gonna love me for!

Run your script with the `-i` flag!

By doing so, you get a REPL when the script finishes, EVEN with errors πŸ’£

1/4
Let me show you an example.

Below is a piece of code I wrote in a script called `foo`.

If you look closely, you'll see I'm generating 100 random integers...

All of them between 0 and... 0! So I'll generate 100 zeroes (my bug).

Later, a 0/0 division will throw an error.

2/4
When I run the code with the `-i` flag, the terminal shows the error and immediately opens a REPL!

From within the REPL I can inspect my variables and figure out what went wrong!

Isn't this amazing ⁉

3/4
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(