Transcript from the "Python Philosophy" Lesson
>> Nina Zakhareko: Python has an interesting philosophy, The Zen of Python, it's a list collection of 19 software principles written in poem form, that influence the design of the Python Programming Language and,
>> Nina Zakhareko: Kinda really captures, I feel like the essence of it. It was published on a Python mailing list in June of 1999 by Tim Peters.
[00:00:25] As we learned yesterday, Python is 30 years old, Python 3 is 11 years old, so it's gonna be old enough to vote soon, right? [LAUGH] So a cute little Easter egg in Python, The Zen of Python is in the Python interpreter. So you should all have your REPLs open, type import this and press Enter.
[00:00:51] But I'm gonna talk through some of the first principles, I recommend coming back and looking at the rest later. So The Zen of Python starts with, beautiful is better than ugly, explicit better than implicit, simple better than complex, complex better than complicated, it's an important one, an important distinction.
[00:01:12] Flat better than nested, sparse is better than dense, readability counts, so these are really important Python ideas. Simple is better than complex, generally Python programmers prefer to be explicit and write simple, understandable, and maintainable code, instead of maybe doing some ego flexing and writing things that are unnecessarily complex.
[00:01:40] Sure as developers, we've all seen things that didn't just didn't need to be that complicated. Readability counts, making your code easy to read, avoiding single character variable names. Calling your functions with named parameters where applicable, using good variable names.
>> Nina Zakhareko: And this is really, I feel like, really ties in hand with PEP 8.
[00:02:06] We learned about PEP 8 yesterday, how it's an important style guide for Python developers because most good Python code should look pretty similar. And that really helps in terms of readability, right, you know all the imports are going to be at the top. You know if something is named with camel case then it's likely to be a class.
[00:02:25] Your variables are all lower class and divided by underscores.
>> Nina Zakhareko: I have a few more fun Easter eggs to show you. So I'm going to start my REPL here.
>> Nina Zakhareko: Let's see, where did my REPL go? No, looks like my REPL crashed. So if this happens to you, if you see any, weirdness, things aren't working as you're as expected, so set this trash can here, and it'll blow that away.
[00:03:05] And let's try that again, awesome.
>> Nina Zakhareko: Okay, so our next Easter egg, we can do from __, remember those double underscores are also called dunder in Python, from __future__ import braces,
>> Nina Zakhareko: That's not happening.
>> Nina Zakhareko: And one of my favorite Easter eggs if you import antigravity.
>> Nina Zakhareko: Should see a fun little XKCD.
[00:03:51] Maybe one of my favorites, which just says, YOU'RE FLYING! HOW? PYTHON! I LEARNED IT LAST NIGHT! EVERYTHING IS SO SIMPLE! HELLO WORLD IS JUST print "Hello world!" in Python 3, put parentheses around this. There's dynamic typing and there's the white space, it's a whole new world. So if you ever need a little pick me up just import antigravity.