Send Close Add comments: (status displays here)
Got it!  This site "www.robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
The Python programming language
by RS  admin@robinsnyder.com : 1024 x 640


1. Python
Python is a general purpose programming language.

Python is powerful... and fast; plays well with others; runs everywhere; is friendly & easy to learn; is Open. From the Python web site at https://www.python.org/.

2. Python overview
What is a python? A python is a snake.

The programming language Python comes from the British comedy group Monty Python

3. Python
Python is a simple interpreted object-oriented programming language system that has extensive standard libraries that can be used for many types of practical programming. Python runs on many different platforms and has been ported to the Java and .NET virtual machines. It is distributed under an open source license that makes it free for even commercial products. The official Python web site is at http://www.python.org.

4. Versions
Python 1.0 was first released in 1991. It was conceived by Guido van Rossum.

Python 2.0 was released in 2000. The current version is 2.7. Support for Python 2.x is due to be discontinued in January 2020.

Python 3.0 was released in 2008. The current version is 3.7.

Python has a simple syntax that uses indentation rather than begin/end or curly braces.

5. Python 3,x
Python provides extensive support for many functional programming capabilities.

Python 3.x provides better support for asynchronous, parallel, and concurrent programming.

There is an extensive library of functionality available (all versions).

The package manager is called pip.

6. Core philosophy
Core philosophy (from Wikipedia): From Wikipedia:

Python embraces a "there should be one—and preferably only one—obvious way to do it" design philosophy.

To describe something as 'clever' is not considered a compliment in the Python culture.

One often hears/reads the phrase: "Thy Pythonic way of doing it is ...".

7. One way to do things
In many programming languages (e.g., C, Java, etc.) there is more than one way to write an if statement.
// one way - curly braces if (b) { x+= 2; } // another way - no curly braces if (b) x += 2; // other ways - change indent on curly braces

Due to style considerations, one should not use the second form above (always do similar things in the same way).

Python only has one way so there is no choice.
if b: x += 2;

Note that the parentheses around the boolean expression b are not needed in Python.

8. Hello world in Python
The file type of a Python program file is py.

The following Linux command(s) create/edit a hello program in the your home directory using the nano text editor.
nano ~/hello.py

Create the following program text in the editor that will output the text "Hello world"
print("Hello world")

To exit with save, remember to press Ctrl-X, then "y" (for yes) and Enter to exit.

The following Linux command(s) run the program.
python ~/hello.py

The output should be as follows.
Hello world


9. Program: decimal to binary
Let us look at a program to implement to algorithm for decimal to binary conversion.

The routine toBinary1 takes as input a value and returns the string representation in binary (base 2)

The first part of the program will use the hard-coded value of 156.

The second part will use a loop to output the decimal values and binary representations of the values from 0 to 16.

10. Python code and output
Here is the Python code [#1]

Here is the output of the Python code.


11. Java comparison
For comparison, below is the above Python code example in Java.

12. Java code and output
Here is the Java code [#1]

Here is the output of the Java code.


13. End of page

by RS  admin@robinsnyder.com : 1024 x 640