Introduction

Python is a dynamically typed, interpreted, general purpose programming language. It's useful for everything from system scripting, to web applications, to full graphical desktop programs. Because of that, it's no surprise that demand for Python programming skills is only increasing, and top companies like Google, Mozilla, Instagram(Facebook), and Reddit rely on it as part of their core technology stack. Not only that, but Python is a favorite in both academic and scientific circles and is gaining ground in the financial sector. Top universities are even using it to teach programming in their computer science programs.

With all of that said, you'd probably be thinking that Python is something super difficult to learn and only accessible to the elite in the technology field, but you couldn't be more wrong. Python is easy. Python is really easy. In fact, Python is one of the first languages used to teach children to program. Python was designed to be very clear and simple to understand. It reads like plain English, and its syntax makes use of spaces rather than brackets and semicolons, so it always looks clean and uncluttered. It's very difficult, if not impossible, to wright messy Python. This helps out new programmers and programmers new to Python big time because you can always tell what you're looking at, or at least, get a decent sense of what it does. This way, you can look at code examples from established open source projects to get an idea of what professional grade Python looks like and how it's used.

Python and Linux work incredibly well together. It wasn't all that long ago that Python supplanted Perl as the de facto scripting and "glue" language on Linux systems. This means that many scripts and utilities that ship with modern Linux systems are written in Python. As a result, most Linux distributions have Python installed by default, but there is a bit of a catch. There are two current versions of Python. Python 2.7.X and Python 3.X.X are both current. Syntactically, they are very similar, but Python 3 has some features that Python 2 doesn't. That means that they are not entirely compatible and many distributions package them separately. So, your system may have Python 2, but not Python 3 or vice versa. This guide and the others in the series are going to cover Python 3. It is the future of Python, and it's not so bad to go back to Python 2 after you've worked with Python 3.

Installing Python

You may not need to install Python on your system. The current setup may be exactly what you need. However, if not, the rest of this guide will be dedicated to telling you how to install both Python versions, so you can be sure that you have everything that you need going forward.

Debian/Ubuntu/Mint

Debian based distributions break up Python 2 and Python 3 packages, and they refer to them separately as well. Python 2 is referred to just as Python and Python 3 is referred to as Python3.

Python 2
$ sudo apt-get update
$ sudo apt-get install python
Python 3
$ sudo apt-get update
$ sudo apt-get install python3

Fedora

Much like the Debian based distributions, Fedora designates Python 2 as Python and Python 3 as Python3.

Python 2
# dnf install python
Python 3
# dnf install python3

CentOS

CentOS actually doesn't package Python 3 by default. It is available from Fedora's EPEL repository, though, so installing it isn't a problem, once you've enabled the repository on your system.

Python 2
# yum install python
Python 3
$ wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
$ su
# rpm -i epel-release-latest-7.noarch.rpm
# yum install python34 
If you want to add the repository key, it is available on Fedora's website https://getfedora.org/keys/.

OpenSUSE

OpenSUSE is a lot like Fedora and the Debian distributions. Python is broken into Python 2 and Python 3 packages that are installable separately.

Python 2
# zypper in python
Python 3
# zypper in python3

Arch Linux

Arch is actually the exact opposite of the others. Arch uses Python 3 by default and packages Python 2 separately. Python 2
# pacman -Syu
# pacman -S python2
Python 3
# pacman -Syu
# pacman -S python

Gentoo

Python is heavily integrated into Gentoo. Gentoo's package manager, Portage, is written in Python, as are many critical scripts. Because of this, both versions of Python are installed by default on Gentoo. If you want to change which versions of Python the system uses, you can specify them in /etc/portage/make.conf and run a full system upgrade. /etc/portage/make.conf
~~~~~~~~~
PYTHON_TARGETS="python3_4 python2_7"
~~~~~~~~~
# emerge --sync && emerge --ask --update --newuse --deep --with-bdeps=y @world
You can choose the version of Python in use with eselect.
# eselect python list
# eselect python set 2
Be very careful messing with Python version in Gentoo. Since so much of the system is tied to Python, it is very easy to break things. Your best bet is to leave things alone, unless you know exactly what you're doing.

Table of Contents

  1. Python Introduction and Installation Guide
  2. Python Files and the Interpreter
  3. Experimenting With Numbers and Text In Python
  4. Python Variables
  5. Working With Number Variables In Python
  6. Python String Basics
  7. Advanced Python Strings
  8. Python Comments
  9. Python Lists
  10. Python List Methods
  11. Python Multidimensional Lists
  12. Python Tuples
  13. Python Boolean Operators
  14. Python If Statements
  15. Python While Loops
  16. Python For Loops
  17. Python Dictionaries
  18. Python Advanced Dictionaries
  19. Python Functions