Python
Python
Python is a widely used high-level programming language used for general-purpose programming, created by Guido van Rossum and first released in 1991. Python has a design philosophy which emphasizes code readability. You'll often find that your first guess at what a function is called is surprisingly correct.
For instance, if you want to print something, you write:
Also, it's true. Python's name is derived from Monty Python.
Python Console
Python has an interactive console you can use in your terminal. Type python3
to get started.
Note: there are two versions: Python2 and Python3. We'll be using Python3. If you ever type simply python
in the terminal the terminal will assume you mean Python2. Python3 is better.
Philosophy
The core philosophy of Python is summarized by the document The Zen of Python , which includes aphorisms such as:
Beautiful is better than ugly
Explicit is better than implicit
Simple is better than complex
Complex is better than complicated
Readability counts
Familiar Datatypes
Python has all the data types you're used to using in JavaScript. Python has variables, functions, booleans, integers, floats, strings, lists and dictionaries (objects). You never declare var
in Python.
This is all legal Python:
Negative String Indexes!!
Python has some little features that make code really sweet to write. Negative string (and array) indexes is simply one example of great syntax options Python offers.
Whitespace
Python never uses curly braces to define blocks of code. Instead, it forces programmers to write their code with proper whitespace. Many people find this annoying and you're bound to hear people scoff at Python for this decision.
Here's what a for loop and an if else statement look like in Python. The whitespace is important! You have to consistently indent with tabs, or spaces. Whichever you choose you have to be consistent with how many tabs or spaces you use at each level!
Notice that Python uses a weird word elif
for "else if" statements.
Functions
Python allows you to define functions with parameters. Parameters can even be declared with default values in case you want to call a function without passing in parameters:
For Loops
There's no for (var i = 0; i < a.length; i++)
for loops in Python. All for loops in Python use automatic iterators, like this:
Python comes with lots of built in libraries. We're able to import all sorts of useful tools.
Ever wanted to shuffle an array?
Ever wanted to choose one random thing from a list?
That's just a small taste. Let's see what else Python has to offer!
Last updated