Python

Life is 10% what happens to us and 90% how we react to it. If you don't build your dream, someone else will hire you to help them build theirs.

Python

Introduction

Python has a unique culture and community based on its core design philosophy of readability and syntax, that enables you to write concise programs. In this course, we will provide an overview of Python’s design philosophy, as well as how to install Python 3 on Linux. We’ll also show you how to write a basic program with built-in data
types, loops, and conditionals.

An Overview of Python

To begin with, let’s take a look at some of Python’s features. Python is open source, which means it’s free to obtain, modify, use for any purpose, and redistribute. It’s quick to learn, which means that you get up to speed, programming, very rapidly. It’s easy to read and understand, which makes it easy to maintain your programs over time. It’s very powerful, with many different modules provided for lots of capabilities. And you’ll find it used throughout many different programming domains. As far as Python’s technical features, it is an object-oriented language. Although, you can use procedural and functional programming styles, as well.

Variables are dynamically typed. And given their type; add assignment. As opposed to declared, with a type; the way that static languages do. It’s strongly typed because, once an object has its type, that type determines what methods or functions can be used with that object. In loosely typed languages, objects can be coerced to perform functions that its type would not normally allow. It’s white space delimited. So instead of using keywords or braces to delimit blocks of code, Python
uses indentation, where typically, four spaces are used to indent each block of code.

It’s interpreted, which may make it execute slower than compiled languages. But it allows for the programmer to interact directly with the interpreter, and inspect code objects, without having to recompile. Python comes in many different editions. CPython is the standard type, where Python is implemented in the C programming language. Jython is Python implemented within a Java virtual machine, which allows for the programmer to blend Python and Java libraries. Iron Python is for Windows, which implements Common Language Runtime, and allows for the mixing of .Net assemblies in Python libraries. And finally, PyPy is Python implemented in Python; and, with its Just-In-Time compiler, is one of the fastest editions. Like the other non-standard editions, it provides solutions for some of the weaknesses of CPython.

As far as Python’s ubiquity, you’ll find it everywhere. It’s very popular on the Web; with major frameworks, such as Django and Zope, allowing for the easy creation and management of web sites. It has the blender project, which allows for the creation, manipulation, and animation of 3D models. And it’s used by desktop applications. Not only to create plugins in advanced programs, such as GIMP, a Photoshop clone, but also to create applications like Dropbox. If you don’t think you can have any fun with Python, then you really ought to check out the Pygame project. This framework provides the ability to use animation, music, sound, and devices within a game. Python is also very popular within the scientific community, through packages such as SciPy and NumPy, providing advanced mathematical functions.

The Philosophy of Python

Let’s have a little pep talk about Python. PEPs, or Python Enhancement Proposals, can be submitted by anyone who has an idea about how to enhance the Python language. These are then reviewed, rejected, or accepted by the Python community, as a way to evolve the language. PEPs can also be used to provide guidelines. Some examples of PEPs include PEP 0, which is an index to all of the PEPs; PEP 1, which states the purpose of each PEP; and PEP 8, which is the Python code style guide. The Python philosophy is stated by PEP 20, which is known as the Zen of Python.

This PEP 20 lays out the design principles for Python code. It states 20 aphorisms, but only 19 have been written down. Although all of the PEPs are available online, this particular PEP is accessible from within the Python shell. If you execute import this inside of a shell, you’ll be able to read the Zen of Python. Python is not named after the snake. Python is named after a 1970s comedy troupe that the creator of Python, Guido van Rossum, was a big fan. Consequently, there’s many things about
Python that have kind of a lighthearted, or comedic feel to them.

Some Python terminology that you should know includes Pythonic, where code that follows the Python philosophy, and it’s written in a very native way, it’s considered Pythonic. This is a good thing. Whereas code that looks like it was written in another language, and then ported over to Python, where it is written in kind of a clumsy way, is considered unpythonic. And of course, this is a negative term. If you’re a Python practitioner, you might be called a Pythonista, a Pythonist, or something else that plays on Python.

Python 2 vs Python 3

It’s important to understand that there isn’t just one Python, there’s two main current Python versions. There’s the Python 2.7.9 and 3.4.3 available at the time of this writing. Although it might seem like a small difference, it is significant. Python 2 is still currently in use. However, it will be moved to maintenance after Python 2.7’s final release. Some of the updates from Python 3.x have been back ported to Python 2.7. Beware, if you write code in Python 2, it is not fully compatible with Python 3. Python 3 intentionally broke compatibility with Python 2 in order to make things better.