Python was a hobby project
Guido Van Rossum was looking for a hobby project and choose python in december, 1989.
The Zen of Python
Open your python terminal and type
import this
. This is an easter egg in python.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!
Flavors of Python
Python ships in various flavors:
- CPython- Written in C, most common implementation of Python
- Jython- Written in Java, compiles to bytecode
- IronPython- Implemented in C#, an extensibility layer to frameworks written in .NET
- Brython- Browser Python, runs in the browser
- RubyPython- Bridge between Python and Ruby interpreters
- PyPy- Implemented in Python
- MicroPython- Runs on a microcontroller
No Braces
Unlike Java and C++, Python does not use braces to delimit code. Indentation is mandatory with Python. If you choose to import it from the future package, it gives you a witty error.
from __future__ import braces
Antigravity - Easter Eggs
If you get to the IDLE and type in
import antigravity
, it opens up a webpage with a comic about the antigravity module.Python influenced JavaScript
Python is one of the 9 languages that influenced the design of JavaScript. Others include AWK, C, HyperTalk, Java, Lua, Perl, Scheme, and Self.
_ gets the value of the last expression
Many people use the IDLE as a calculator. To get the value/result of the last expression, use an underscore.
>>> 3*5 15 >>> 2*_ 30
for and while loops can have else statements
The else statement is not limited to if and try statements. If you add an else block after a for- or while- loop, the statements inside the else block are executed only after the loop completes normally. If the loop raises an exception or reaches a break statement, the code under else does not execute. This can be good for search operations.
def func(array): for num in array: if num%2==0: print(num) break # Case1: Break is called, so 'else' wouldn't be executed. else: # Case 2: 'else' executed since break is not called print("No call for Break. Else is executed") print("1st Case:") a = [2] func(a) print("2nd Case:") a = [1] func(a)
String literals concatenate together
If you type in string literals separated by a space, Python concatenates them together. So, ‘Hello’ ‘World’ becomes ‘HelloWorld’.
One can return multiple values in Python. See the below code snippet:
Multiple Return Values in Python!
def func(): return 1, 2, 3, 4, 5 one, two, three, four, five = func() print(one, two, three, four, five)
Output:
(1, 2, 3, 4, 5)We can’t define Infinities right? But wait! Not for Python. See this amazing example
# Positive Infinity p_infinity = float('Inf') if 99999999999999 > p_infinity: print("The number is greater than Infinity!") else: print("Infinity is greatest") # Negetive Infinity n_infinity = float('-Inf') if -99999999999999 < n_infinity: print("The number is lesser than Negative Infinity!") else: print("Negative Infinity is least")
Output: Infinity is greatest Negative Infinity is least
This page looks best with JavaScript enabled
Python Fun facts
WRITTEN BY
Ohidur Rahman Bappy
📚Learner 🐍 Developer