Home      |       Contents       |       About

Prev: -       |       Next: What to install

What is Python

Python is...

  • ... a high-level general-purpose programming language

    • high-level: Python is a more abstract language compared to C. This adds expressiveness to Python and offers power to programmers to write more flexible and efficient code. The downsize might be that Python code is slower in occasions, but many optimization methods exist to deal with this issue.
    • general-purpose: Python is not bound to any specific programming purpose (unlike R which is specifically 'statistics-oriented') nor programming paradigm (unlike Java which imposes object-oriented programming techniques). This feature makes Python a powerful tool for a variety of applications in various scientific domains and also in education. The interested developer will find numerous domain-specific packages to start writing specialized code for the domain of interest. The teacher has a versatile tool to advance students' computational thinking.
  • Read Python docs: "What is Python? Executive Summary"

Python promotes...

  • ... code simplicity and readability
    • a) simplicity: Python expression is laconic. Much of Python simplicity comes from the fact that the language is dynamically typed and does not require variable declaration. Also important is that there is no need for brackets of any kind for starting/closing blocks of code, just simply code indentation.
    • Simplicity of code helps to:
      • (a) ...focus on what is important; thus, promote the expression and development of learners' 'computational thinking' without being baffled by syntactic nuances
      • (b) ...increase productivity; writing simple code saves time and money.-

Take a look at the 'Hello World' code in Python compared to two other popular languages.

In [1]:
#### in C
#include <stdio.h>
int main()
{
  printf("Hello World\n");
  return 0;
} 


#### in Java
public class HelloWorld { 
    public static void main(String[] args) { 
        System.out.println("Hello, World!");
     } 
}

#### in Python 3
print('Hello World!')
  • b) readability: simplicity promotes also readability and this is important in development as "a piece of code is written once but is read many times"
In [2]:
# Simplicity and Readability in Python code

garden = ['rose', 'carnation', 'gardenia']

for flower in garden:
    print(flower)

# You are most likely to understand this code lines without any further explanation!  

Python 3.x fully supports Unicode

  • So, you can use any Unicode character in your code
  • The code below is a Greek version of the above 'flower-garden' example
In [2]:
κήπος = ['τριαντάφυλλο', 'γαρύφαλλο', 'γαρδένια']

for λουλούδι in κήπος:
    print(λουλούδι)
τριαντάφυλλο
γαρύφαλλο
γαρδένια

Versions

  • Python historically comes in two versions: 2.x and 3.x
    • 2.x appeared in 2000. It survives until today because of the numerous packages developed and is still used in many domains.
    • 3.x appeared in 2008: it represents the present and future of the language. Start learning the 3.0 version without worrying too much about 2.x (transposing code between the two versions is easy).

BDFL and the Name

Community

The Zen of Python

  • When working with Python remember (among others) that "Readability counts", as the Zen of Python properly declares...:
In [3]:
import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

. Free learning material
. See full copyright and disclaimer notice