5 Fun Python Easter Eggs

Поделиться
HTML-код
  • Опубликовано: 9 июн 2024
  • Here are 5 fun Python easter eggs that you should know about if you love Python.
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels
    00:00 Learning Python made simple
    00:05 Intro
    00:23 Easter egg #1
    01:07 Easter egg #2
    01:43 Secret challenge
    02:22 Easter egg #3
    04:16 Easter egg #4
    04:46 Easter egg #5
    05:08 Why is this here?
    06:10 Summing it up

Комментарии • 73

  • @smergibblegibberish
    @smergibblegibberish 21 день назад +77

    You can see the source code for the `this' module at `this.__file__'. It has purposefully bad code to demonstrate what not to do. That's part of the poetry that a lot of people miss.

    • @joaozin003
      @joaozin003 19 дней назад +4

      And it contains the challenge solution

    • @Hylasavignyi
      @Hylasavignyi 18 дней назад

      Just by looks it seems to be Ceasar Cipher. The decoder table is provided in the same module. Here is a one-liner to recover the text
      ''.join([this.d.get(c, c) for c in this.s])

  • @Un_revealing
    @Un_revealing 24 дня назад +122

    THE braces one made my day

  • @aeghohloechu5022
    @aeghohloechu5022 24 дня назад +105

    5:48 geohasing is another one of xkcd comics which is like a random location generator you can go hiking to.

    • @Joulespersecond
      @Joulespersecond 24 дня назад +22

      It's a play on words with GeoCaching and hashing. The algorithm name is also a joke, because Randall Munroe is the creator of xkcd.

    • @FishDisks
      @FishDisks 24 дня назад +13

      And Munroe is the surname of the creator of xkcd, Randall Munroe, and as he invented the algorithm in the geohashing comic it's naturally named after him.

    • @TheFreaxTux
      @TheFreaxTux 24 дня назад +4

      426th xkcd

  • @ego-lay_atman-bay
    @ego-lay_atman-bay 24 дня назад +51

    I had no idea python HAD easter eggs. I'm so glad I watched your video, because I learned something new.

  • @SilverSuperGamer
    @SilverSuperGamer 20 дней назад +29

    Me: bracing myself for him typing var: str = "..."

  • @russtest
    @russtest 22 дня назад +13

    The first Easter egg is an example script for the Freeze utility that comes with Python. The instructions for Freeze uses the `hello.py` file so you can test it out.
    Per the Github repo for Python:
    ```
    Freeze make it possible to ship arbitrary Python programs to people
    who don't have Python. The shipped file (called a "frozen" version of
    your Python program) is an executable, so this only works if your
    platform is compatible with that on the receiving end (this is usually
    a matter of having the same major operating system revision and CPU
    type).
    The shipped file contains a Python interpreter and large portions of
    the Python run-time. Some measures have been taken to avoid linking
    unneeded modules, but the resulting binary is usually not small.
    ```
    Originally the Hello script would print `Hello World` just by importing the module. Starting in Python 3.11 it uses the `main()` function.
    I love these Easter Egg videos. I end up falling down a rabbit hole and learning a lot more than just the Easter egg.

  • @AsgerJon
    @AsgerJon 24 дня назад +27

    __hello__ was added in python 3.11

  • @thefanboy3285
    @thefanboy3285 24 дня назад +20

    1. Fellas, I need your help to conclude a debate once and for all : the correct way to print "Hello World!" is without a comma? or "Hello, World!" with a comma ?
    2. I did not know any of these. I'm kinda new to python.
    3. I'm gonna mess with an entire codebase by importin braces everywhere lmaooo

    • @osnofla13ify
      @osnofla13ify 24 дня назад +9

      No comma, it's part of the fun.

    • @Indently
      @Indently  24 дня назад +21

      I think what you meant was:
      No comma it's part of the fun.

    • @callbettersaul
      @callbettersaul 24 дня назад +1

      Neither is correct, because "world" isn't someone's name (to my knowledge :D) and should be lowercased. Other than that, I'm pretty sure, that with comma is grammatically correct, but almost no one uses it there.

    • @ahmoin
      @ahmoin 23 дня назад

      @@callbettersaul _Hello World_ is a title tho

    • @haipingcao2212
      @haipingcao2212 20 дней назад

      ​@@ahmoinno

  • @davidagnew8465
    @davidagnew8465 23 дня назад +6

    Python provides another module, *codecs*, that decodes this.s:
    Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 2023, 23:49:59) [MSC v.1934 64 bit (AMD64)] on win32
    import this
    ...[poem elided]....
    import codecs as c
    print(c.decode(this.s, 'rot13'))
    ...[decoded poem elided]...
    So, we see that rot13 is one of the many batteries included in Python.

    • @david-komi8
      @david-komi8 20 дней назад +3

      You can pretty much do the same thing with instance and static methods without importing anything; print(this.s.translate(str.maketrans(this.d))). But it's good to know anyways :)

  • @mikejohnston9113
    @mikejohnston9113 24 дня назад

    These are great! thanks

  • @SolathPrime
    @SolathPrime 24 дня назад +7

    [ 2:13 ]: this is actually easy it's just the alphabet shifted and can be solved vary easily

    • @shikanokonokokoshitantan
      @shikanokonokokoshitantan 24 дня назад +1

      You dont need to do that since the dictionary to translate it already exists in the module, "this.d", and the raw string is, "this.s"

    • @SolathPrime
      @SolathPrime 24 дня назад +2

      @@shikanokonokokoshitantan that dictionary is actually generated on runtime meaning it was not hardcoded

    • @shikanokonokokoshitantan
      @shikanokonokokoshitantan 24 дня назад +1

      @@SolathPrime Then that means that the module hardcoded, ofc I am not saying that value is defined WITH the module I am saying that its defined WITH the STRING that is PRINTED when you import this, using the dictionary you can decode this.s using a simole for loop or using a list comprehension.

    • @david-komi8
      @david-komi8 20 дней назад +2

      Stop fighting, it's as simple as writing "print(this.s.translate(str.maketrans(this.d)))"

    • @david-komi8
      @david-komi8 20 дней назад +1

      And also, I'd like to mention that the method used to rotate the alphabet is ROT13, which rotates the alphabet 13 places.

  • @darlinginc.3653
    @darlinginc.3653 20 дней назад +2

    damn thanks for telling me how i can print hello world! i was actually struggling for a bit with it had to type it out 100x times and misspelled it a lot

  • @ERRORRubiksZeraBrand
    @ERRORRubiksZeraBrand 24 дня назад +3

    1:48 i have translated the message, it's just caesar chiper. it returns:
    Beautiful is better than ugly.
    Explicit is better than implicit.
    Simple is better than complex.
    Complex is better than complicated.
    Flat is better than nested.
    Sparse is better than dense.
    Readability counts.
    Special cases aren't special enough to break the rules.
    Although practicality beats purity.
    Errors should never pass silently.
    Unless explicitly silenced.
    In the face of ambiguity, refuse the temptation to guess.
    There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch.
    Now is better than never.
    Although never is often better than *right* now.
    If the implementation is hard to explain, it's a bad idea.
    If the implementation is easy to explain, it may be a good idea.
    Namespaces are one honking great idea -- let's do more of those!
    IT'S THE SAME THING

    • @1vader
      @1vader 23 дня назад

      Yeah, iirc the cipher text is what is stored in thr source code so that the easter egg is somewhat hidden. But it already decodes it for you when you run it. So the d and s aren't additional easter eggs, they are implementation details.

  • @paweleke123
    @paweleke123 21 день назад +2

    instead of _hello_ why not just use constant for the string?

  • @tema5002
    @tema5002 16 дней назад +1

    lmao i have modified built-in json library and call it antigrav (dont question why) and uploaded to pypi
    i discovered antigravity is a thing only now now i feel like i made a cheap copy

  • @dipeshsamrawat7957
    @dipeshsamrawat7957 24 дня назад

    Broh, may I please know which software do you use to create your very good Thumbnails and icons??

  • @JinYuanz11
    @JinYuanz11 24 дня назад

    Thank you

  • @EdKolis
    @EdKolis 7 дней назад

    That antigravity thing reminded me of a video I just watched about MS Office macro viruses. Who thought it was a good idea to give a programming language the ability to open a browser window?

  • @shikanokonokokoshitantan
    @shikanokonokokoshitantan 24 дня назад +1

    Eyy second again!

  • @user-hr8rc1of3x
    @user-hr8rc1of3x 15 дней назад

    Geohashing is reference to another xkcd webcomic

  • @leightaylor8069
    @leightaylor8069 22 дня назад

    What is a datedow, and why is it needed?

  • @DrDeuteron
    @DrDeuteron 24 дня назад +1

    how did I not know any of these? (other than this, everyone knows that)

  • @Shuflduf
    @Shuflduf 20 дней назад

    what IDE/text editor is this?

    • @ramprasathmk
      @ramprasathmk 18 дней назад

      PyCharm IDE for Python Developers

  • @captheobbyist6434
    @captheobbyist6434 12 дней назад +1

    the "this.d" is the decoding table for "this.s"
    inline solution: print(''.join([this.d[i] if i in this.d else i for i in this.s]))
    i loved solving this

  • @contemporarychemists
    @contemporarychemists 24 дня назад +4

    Huh all good but the first one
    Now we need help to print hello world 😢

  • @Asparion
    @Asparion 3 дня назад

    c# coders would flip at the braces thing.. oh wait, don't i know a bit of c#- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

  • @comandanteej
    @comandanteej 24 дня назад +15

    print(''.join([this.d.get(x,x) for x in this.s])) -- is there a more pythonic way to do it?

    • @denizsincar29
      @denizsincar29 24 дня назад +4

      yes there is.
      ''.join(map(this.d.get, this.s, this.s)

    • @EvanED
      @EvanED 24 дня назад +1

      I will leave it to you to decide about the comprehension versus map, but at least remove the explicit list comprehension if you stick with something like that. You can remove both square braces, and unless I am missing something it will still work. What you would doing instead is called a generator expression. Generally, you need to use parentheses around a generator expression, but there are sometimes when you can omit them because they would just be duplicative. Duplicative. Passing a generator expression as a single parameter to a function is one such time.

    • @avxqt966
      @avxqt966 24 дня назад +6

      also
      import this
      import codecs
      print(codecs.decode(this.s, 'rot13'))

    • @Indently
      @Indently  24 дня назад +4

      That's interesting, I didn't know it was encoded using ROT13!

    • @DDvargas123
      @DDvargas123 24 дня назад +3

      `print(this.s.translate(str.maketrans(this.d)))`

  • @xxlarrytfvwxx9531
    @xxlarrytfvwxx9531 18 дней назад

    1:28 I have a shortcut to this on my desktop.

  • @camiloamadio
    @camiloamadio 23 дня назад +1

    Las Malvinas son argentinas!!!

  • @theuntitledgoose
    @theuntitledgoose 24 дня назад +1

    early

  • @Etchacritic
    @Etchacritic 24 дня назад +1

    Almost decodes the this.s message correctly. The only problem is that when you import this, you immediately get the text, so when you run this on the command line, it prints it out twice.
    python -c 'from this import d, s; j = d; j["
    "] = "
    "; j[" "] = " "; print("".join([j[x] for x in list(s) if x.isalpha() or x == "
    " or x == " "]))'

    • @david-komi8
      @david-komi8 20 дней назад

      Is much better to use this.s.translate and str.maketrans like this;
      import this
      print(this.s.translate(str.maketrans(this.d)))
      You can make it shorter by importing s and d directly, but the point is that you can use the dictionary and the translate method to do the work.