Mike Driscoll Profile picture
Nov 27 β€’ 10 tweets β€’ 5 min read
#Python has several Easter eggs built in! 🐍πŸ₯šπŸ£πŸ‡

An Easter egg is a fun little surprise in a programming language, video game or movie.

Let's talk about some of Python's cool Easter eggs!

πŸ§΅πŸπŸ‘‡
πŸ₯š1️⃣ - The most famous #Python Easter egg is probably The Zen of Python, which you will see if you "import this"
πŸ₯š2️⃣ - What you might not know is that Zen of Python's source is really interesting too:

github.com/python/cpython…
πŸ₯š3️⃣ - The next most well-known Easter egg in #Python is probably "import antigravity"

If you type that in your Python REPL, you will be taken to this XKCD comic: xkcd.com/353/
πŸ₯š4️⃣ - Create "Hello World" with an import in #Python!
πŸ₯š5️⃣ - Let's try and import braces in #Python!

Nope! That Easter Egg won't let us!
πŸ₯š6️⃣ - This Easter Egg is kind of tricky. It's for the math nerds in #Python

If you hash infinity in Python, you get back a representation of Pi

If you hash NAN, you will get zero
πŸ₯š7️⃣ - Barry Warsaw, a longtime #Python core developer, was nominated "Friendly Language Uncle For Life" or FLUFL

If you do this special import, the inequality operator "!=" is replaced with "<>"
There are a few other Easter eggs mentioned in this curated list of Easter Eggs in Python on GitHub:

github.com/OrkoHunter/pyt…
Thanks for reading my fun little thread on #Python Easter eggs! πŸπŸ‡πŸ₯š

Follow me for more neat content on the Python language!

β€’ β€’ β€’

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

Keep Current with Mike Driscoll

Mike Driscoll 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 @driscollis

Nov 29
Today I am going to show you how to create 7️⃣ different file types with #Python:

🐍 Text file
🐍 CSV
🐍 XML
🐍 JSON
🐍 Tar file
🐍 PDF
🐍 Excel

Join me for this fun πŸ§΅πŸ‘‡
1️⃣ Creating a text file with #Python is a breeze! The recommended method is to use Python's `with` statement as it will automatically close the file for you

That means you can create a text file with TWO lines of code if you want to: Image
2️⃣ Creating a CSV file with #Python can be accomplished using the `csv` module

Here's a small example: Image
Read 16 tweets
Nov 28
Let's talk about creating dictionaries with #Python 🐍

A dictionary is a key / value pair. The key must be of an immutable type, such as an integer or a string. The value can be of any type

πŸ§΅πŸ‘‡
You can create a #Python dictionary in several different ways.

The following shows the most common method of dictionary creation followed by using a dictionary comprehension Image
You can also create a #Python dictionary by using the `dict()` function Image
Read 4 tweets
Nov 27
Another great tool in #Python's `collections` module is the `defaultdict`! 🐍πŸ”₯

`defaultdict` is a subclass of the built-in dict class where the first argument is a factory attribute.

πŸ§΅πŸπŸ‘‡
Let's start out by creating a regular dictionary so you can see how `defaultdict` might help clean up your code.

Here you create a dictionary based on words in a string using a conditional statement to add the various words.

You can also see the output in the 2nd screenshot
Now if you use a `defaultdict` with an `int` factory, you can get rid of the conditional statement entirely, which makes your code shorter and easier to read! 🐍πŸ”₯
Read 8 tweets
Nov 24
Another great tool in #Python's `collections` module is the `defaultdict`! 🐍πŸ”₯

`defaultdict` is a subclass of the built-in dict class where the first argument is a factory attribute.

πŸ§΅πŸπŸ‘‡
Let's start out by creating a regular dictionary so you can see how `defaultdict` might help clean up your code.

Here you create a dictionary based on words in a string using a conditional statement to add the various words.

You can also see the output in the 2nd screenshot ImageImage
Now if you use a `defaultdict` with an `int` factory, you can get rid of the conditional statement entirely, which makes your code shorter and easier to read! 🐍πŸ”₯ ImageImage
Read 8 tweets
Nov 23
Today is a great day to learn about #Python's `argparse` module!

The argparse module makes it easy to write user-friendly command-line interfaces.

#PythonStdLib 🐍πŸ”₯

πŸ§΅πŸ‘‡
Here is an example of creating an argument parser with no arguments.

Why would you do that? Well, to find out what `argparse` gives you out of the box πŸ“¦!

You can see here that `argparse` gives you some help text and prints out your provided description Image
A common coding pattern for argument parsing is to put the argument parsing code into its own function or method and then return the parsed args.

Here's an example: Image
Read 8 tweets
Nov 23
Did you know you can create mobile applications with #Python and @kivyframework?

You can! I wrote an article about the process @realpython

realpython.com/mobile-app-kiv…

Let's look at a few examples from the article!

πŸ§΅πŸπŸ‘‡
This is a "Hello World" type example using the @kivyframework in #Python

It basically creates a window with a label on it:
Labels are useful, but a picture is worth a thousand labels!

In this code snippet, you add a picture to your Kivy application instead of a label! 🐍πŸ”₯
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!

:(