Python

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Getting Started

Are you brand new to Python? See My tutorial page to get started.

Python in One Hour is a presentation that should take about 1 hour to work through. It has all of the basic language elements.

Why Python?

People who haven't seriously coded in Python don't appreciate Python. That's because it's hard to understand what Python is about from the perspective of other languages. Python borrows so many features of other languages and brings them together into a cohesive whole that is simply unimaginable until you experience it for yourself.

I believe it takes one big project that is behind schedule coded in Python to really help people appreciate Python. When you're maxed out, and you just want to focus on getting something working, then Python is there to save you. It just works.

The principle feature of Python is that I don't have to think about Python when I write Python code. It's like how I love English because I don't have to think about English when I use it! Well, most of the time at least. I am sure people who do not speak English as their native language disagree with me, but they would say the same of their own language.

Finally, Python follows the rule of the Principle of Least Astonishment. It's one of the doctrines of the language. This means a lot of things are explicit where they are implicit in other languages. It also means that there isn't much magic. Bottom line, Python will not surprise you once you learn a few basic things. This is very important for a programming language. Less surprises means less time spent debugging.

What is Python?

This is really hard to answer well.

Python is a Programming Language. Like all programming languages (should), it tries to make the job of telling the computer what to do easier.

Python is a Program that executes code written in that programming language. This program includes elements such as a Compiler.

Python is a Community where people help each other out and work together to build something greater than if they worked alone.


Describe the Python Language

At a high level, a Python program consists of statements and expressions. Among the variety of statements are statements that all the definition of classes and functions (class, def, @), statements to control program flow (if, for, while, break, continue, yield) and others. Among the variety of expressions are function invocations, basic math and arithmetic operations you'd expect in any programming language, and some other things.

See Python/Language for a more-or-less complete description of the entire language.

You could probably write the entire language on a postcard, since there really isn't much to it beyond what I described above. The details are rather simple, though unbelievably so. Once you understand the concept that Python is not Language X despite looking like Language X, you will do well.

The Python Language supports Procedural Programming, Object-Oriented Programming, Aspect-Oriented Programming, Parallel Programming, Functional Programming, and many others, and probably some no one has thought of before. Although other languages may have a more concise language, it isn't difficult to get Python to adapt to your style of programming.

Magic

The most magical things in Python are (in order of magicality, high to low)

  1. Coroutines.
  2. Metaclasses.
  3. Generators.
  4. Descriptors.
  5. Comprehensions.

After that, there isn't much magic. These things baffle people because they come from 'bad' languages and their implicit assumption that there are lots of hidden corners with dark magic are no longer valid.

These features are not so common in other languages but trivial to master.

Fedora Notes

Fedora ships with Python. These are the packages you need if you intend to do development on Python:

  • python
  • python-devel
  • python-docs: Puts the docs in /usr/share/doc/python-docs-<version>. Browse to /usr/share/doc/python-docs-<version>/html/index.html.

See Also

Good Reading