Python 🐍 docstrings πŸ“ are very important, because they are the first level of documentation of your code.

Docstrings are great because IDEs can often display them, to give you help, when you start using a function.

Here's some advice on how to write them πŸ‘‡πŸ§΅
The first line of a docstring should be a short sentence explaining, in English, what the function does.

Write the docstring as a command, not as a long-winded description of what is going to happen.

Go straight to the point, make that line count!
If the function isn't trivial, you need to write a more complete docstring.

Explain what the arguments do and the return value.

Explain what/when the function raises errors.

Let the user know of any side-effects that might happen.

...

Write all of this after a blank line.
Try to get in the habit of writing docstrings for ALL your functions.

You will get used to it quickly, and it will start to pay off dividends even more quickly!

There's much more to be said about docstrings, but I'll sign off for now.

See you soon πŸ‘‹

β€’ β€’ β€’

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

13 Oct
🚩🐍 Here's a 4-step roadmap to mastering Python!

The roadmap will take you from complete beginner to building real-world Python apps πŸš€

We'll leverage β€œThe Indie Python Extravaganza”, a πŸ“š bundle that you can get for free during October πŸ‘‰ leanpub.com/b/theindiepyth…

πŸ‘‡πŸ§΅
1. If you are a Python newbie, then I recommend you start with β€œPython 101”, 2nd edition, by @driscollis.

This will teach you the fundamentals of Python!

But if you want to learn how to code, you need to write code!

Makes sense?
2. That's why you should also take a look at β€œPractice Python Projects” by @learn_byexample, which will have you write small projects.

This will be very important for you to develop a level of comfort with writing Python code!

Next up, you want to write the best code possible!
Read 8 tweets
9 Oct
Everyone knows that giving proper names to variables and functions is the true programmer's bane.

Here's a thread πŸ‘‡πŸ§΅ with do's and don'ts for naming things in Python 🐍

We can only hold a small number of simultaneous ideas in our 🧠, so proper naming can really help us!
There exist a bunch of naming conventions out there.

Some of them are more common in Python, and others are rarely seen in Python code.

Let me just show you what they look like, and then I'll walk you through when you could use each.
The PascalCase convention is often used with classes.

Notice that when you use PascalCase, you should uppercase all letters of an acronym πŸ‘‡

In the image, that's exemplified by the `AIPlayer`, where `AI` stands for β€œartificial intelligence”.
Read 21 tweets
7 Oct
Python 🐍 dictionaries are amazing ✨ data structures.

Do you know how to make the best use out of them?

One method you should have in your arsenal is the `.get` method.

Here's a short thread πŸ‘‡πŸ§΅ about it.
A dictionary is a β€œmapping”: it maps keys into values.

In Python, if you have a key, you can use it inside `[]` to access the corresponding value πŸ‘‡

However, ...
... if the key doesn't exist, then you get an error!

As an example, here's my attempt at getting my age from the previous dictionary, which only knew about my name πŸ‘‡

So, how to try and access keys without having Python throw an error at your face..?
Read 12 tweets
6 Oct
πŸ†Β Here's a mini Python 🐍 challenge.

You have an int `value` and a dictionary `my_dict`.

`my_dict` **may** contain a key `"field"`, with an int.

If `"field"` is there, add it to `value`.

How would you solve this?

Here's a short thread πŸ‘‡πŸ§΅ with a couple of solutions.
First off, this mini thread was prompted by @svpino's most recent tweet, that I include here for credit and context:

Like Santiago pointed out, there are two archetypes of solutions here.

The first one, is to check if the `"field"` is there, and then add to `value`.

Simple to understand, but with one β€œdrawback” that bothers me just a little bit... Image
Read 11 tweets
4 Oct
What's the deal with Python 🐍's pass-by-value or pass-by-reference?

How does it relate to mutable and immutable objects?

Here's a Python thread πŸ‘‡πŸ§΅ that'll make everything crystal clear and help you master Python 🐍.

Let's go πŸš€
First thing you need to realise is that Python 🐍 does not use the pass-by-value model...

But it also does not use the pass-by-reference model!

Let me see if I can explain what I mean!

What does it mean to pass by value?
In the pass-by-value model, whenever you call a function with a given argument, that argument is fully copied into the function.

This means you can change what got into your function, and you won't be able to see the changes from the outside.

This _looks_ like pass-by-value:
Read 26 tweets
2 Oct
πŸ› πŸ‘€ On the 23/09 I challenged myself to go from 2.95k followers to 4k by the end of the month 😱

That was +1.05k followers (+36%) in 7 days.

On the 1st Oct I woke up to a little over 6k followers πŸŽ‰πŸ”₯ that's INSANE!

Thanks for your support!

Here's a recap of these days πŸ‘‡πŸ§΅
First off, for reference, here is the original tweet with the public challenge:

In the original tweet I said that my strategy would be to publish a high-value thread each day.

For my challenge to be met, I had to grow β‰ˆ4% each day.

Here's a breakdown of the number of followers I woke up to each day, with the % change relative to the previous day.
Read 13 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!

:(