Python, for easy programming
Python code must be indented
(Monty Python at work )
A day is enough to start programming with Python and you can write scripts in a few hours while you need for days with some other languages. Is is an interpreted language widely used and cross-platforms.
It has powerful features such as lists, tuples, dictionaries that allow you to translate your ideas into lines of code easely.
These integrated lists make it a successor to Awk and any other word processor language.
The name is a tribute to the comedy group "Monty Python", but the snake with the same name is also the symbol of the language.
The creator of the language, Guido Van Rossum, was Google employee from 2005 to 2012 and works for Dropbox since.
Designed after the ABC language that was a model for simplifying a programming language (the variables for example retain their value from one session to another), Python is initially a very easy to read language.
But programmers never resist their evil demon that incites to write more and more convoluted and crytographic code, bringing the language to have an evolution in the complication that with the time make it approaching C++. The same function in the same language can become less and less comprehensible to the delight of the "genius programmer".
Although if it is here since 2008, Python 3 still knows only marginal use in 2013 compared to Python 2. The incompatibility with previous versions, without making performance gain, discourages transition. Fear that the existing libraries are not compatible, which is often the case, also hinders its adoption.
A dynamic scripting language
This scripting language may be used on the server or for applications.
- It is originally interpreted, but compilers exists and versions for the JVM or .NET.
- It is object oriented.
- Variables are dynamic, the type is not declared and may change.
- Indentation is used for block recognition and this is unic to Python.
- Tuples are variables or object packed all together, for functions' return, for example.
- Lists and dictionaries are other built-in composed objects.
- Functions may be embedded inside other functions.
- Can be extended with C modules.
Python 3.0 changes the syntax of the language which makes it partially incompatible with the previous ones, to the point that it is considered like a new language by early adopters.
- print x is replaced by print (x).
- Range is now an object and not a list of values.
- No more byte strings, all is unicode.
- <> operator is removed .
- dict.keys returns a view et not a list.
That is often blamed in the language, regardless the version:
- Code execution is slow. This is why it tends to be replaced by Go.
- The object orientation is rather rustic and improvised.
- Using indentation to define a block is a design choice often contested. So if you comment a line, that changes the structure!
- Some builtin global functions should be methods of object instead (but PHP is much worse in this regard).
You can compare the syntax of Python, Ruby and PHP, to judge the readability.
Some examples of code...
Displaying chars of a string:
s = "demo" for c in s: print c
Displaying elements of a list:
listdemo = [1,2,3] + [4,5] subdemo = listdemo[1:3] for num in subdemo: print num
Should print: 2 3 4...
We can make Python programs more easily with a free IDE like Eclipse for which numerous examples of use can be found on the Web, or if we are more involved, a commercial software like PyCharm.
Here is a list of the most popular tools to make Python scripts:
The official distribution with a complete tutorial. Thank to the installer to download, installation is very easy.
- PyCharm by JetBrains.
Specialized IDE, exists as open source and free version.
A free modern tool for interactive development, that won the 2012 Award from the FSF. A version is available for Linux, Windows and Mac.
A Java compatible version. Compile any Python source to bytecode, interpreted by the Java virtual machine. There is also a compiler for .NET, IronPython.