One of the most underrated #Python modules?

`turtle`

We know it's used for teaching & not in the "real-world"

But it's usually used only for basic drawings & simple animations for kids–a very limited scope

We can teach more advanced topics, too…

Here are some examples…

/1
Data structures: lists, tuples, dictionaries, and sets. When to use which one and how to use them.

Here's an animation that uses all four of these structures:

thepythoncodingbook.com/2021/10/31/usi…

/2
And a bit further down the line, here's an example of a `turtle` animation that introduces Named Tuples: thepythoncodingbook.com/2022/06/12/pyt…

/3
Or maybe we want to use it model real-world processes in a quick-and-simple way. Here is a demonstration of "simulating" bouncing balls

There's the single ball version
thepythoncodingbook.com/2021/08/19/sim…

and the many balls one
thepythoncodingbook.com/2021/09/09/usi…

/4
Here are some more ideas from projects I've written up recently

I have loads and loads more which I'll try to write up and publish in the coming months

thepythoncodingbook.com/category/turtl…

/5
I should have added the orbiting planets one, too, which is fun. [There's also a 3D version but that doesn't use `turtle`]

thepythoncodingbook.com/2021/09/29/sim…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Stephen Gruppetta

Stephen Gruppetta 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 @s_gruppetta_ct

Nov 7
Day 10 of the Python Functions Series. Let's talk about type hinting today, or just "typing"

I'll use an example I've used earlier in the series but add type hints to it

—> Will both of these function calls work or will any raise an error?

<code in ALT text>

/1 def greet_person(person: st...
The parameters of the function are:

• `person`
• `number`

The parameters also include a type hint after the colon, right after each parameter name

/2
But these are just _hints_. You can confirm this by running the code above

Both function calls work fine. This is because there's nothing in the code that won't work if `person` is an integer instead of a string!

/3 def greet_person(person: st...
Read 6 tweets
Nov 7
At what stage should a learner jump into the official documentation to figure things out?

If you say right away, you've probably forgotten what it's like to be at the very beginning of the journey

Here's an example…

/1
Take `range()`, for example, which many are curious about early on as they use it when learning the `for` loop (docs.python.org/3/library/stdt…)

Here's the first part of the docs:

/2
class range(stop)
class range(start, stop[, step])
The arguments to the range constructor must be integers (either built-in int or any object that implements the __index__() special method). If the step argument is omitted, it defaults to 1. If the start argument is ...

/3
Read 7 tweets
Nov 6
As we have a one day's break from the Python functions series which returns with Day 10 tomorrow, let's look back the the topic from the last three days:

• positional-only arguments using / in function definitions
• keyword-only arguments using * in function definitions

/1
Why do we need them? Are they even ever used?

I bet you've seen them many times and ignored them. I'll go further and bet you've used them, too, without knowing

/2
Have you ever used `list.sort()` with the `key` or `reverse` parameters?

I bet you have!

Here's the signature for `list.sort()`

sort(self, /, *, key=None, reverse=False)

/3
Read 11 tweets
Nov 6
For those who've been following the #Python Functions Series, today we'll take a short break and Day 10 will return tomorrow – There's still a related-thread later today, but not directly part of the series.

So far we've covered:
• terminology (boring but useful)
• …
• Choosing to use arguments as either positional or keyword
• Using optional arguments by assigning default values
• *args and **kwargs, or variable number of positional and keyword arguments
• Using positional-only arguments, or the "rogue" forward slash / in functions
• …
• Using keyword-only arguments, or the "rogue" asterisk * in function signatures

Next up:
• type hinting
• general best-practices when defining and using functions
Read 4 tweets
Nov 5
In Day 9 we'll bring positional-only and keyword-only arguments together in a single function

Have a look at this example

—> Which of these options will raise errors?

You can refer to the threads from the last two days if you need to refresh your memories…

/1 def greet(greeting, /, repe...
Let's go through all four function calls one at a time

# 1.

All the arguments are positional arguments in this call

This leads to an error

/2 def greet(greeting, /, repe...
The part of the function signature which leads to this problem is the asterisk *

Any parameter after the asterisk must be matched to positional-only arguments

/3
Read 20 tweets
Nov 5
In the series 'weird ways to generate specific numbers'

>>> stuff = ["The Python Coding Book"] * 620
>>> stuff.sizeof()
5000
Here are the previous ones in this dubious series
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

Don't want to be a Premium member but still want to support us?

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

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(