Raspberry Pi 3: Programming and Projects from Beginner to Expert by Bosworth Jim

Raspberry Pi 3: Programming and Projects from Beginner to Expert by Bosworth Jim

Author:Bosworth, Jim [Bosworth, Jim]
Language: eng
Format: epub
Published: 2018-01-18T16:00:00+00:00


What is the difference between Python version 2 and Python version 3?

Python 2 is the version of python that was released in the year 2000, while Python 3 was released more recently, in the year 2008. Of course, Python 3 being the more recent version of the language, this is the version that is currently being supported and developed, and is being used by new applications. The last version of Python 2 is Python 2. 7. 6, which was released in 2013, and there are no further releases expected for Python 2. However, some applications and users still use Python 2, as some code libraries developed to improve functionality of python 2 have not yet been transferred, or “ported” into python 3, leading users to continue using the older version.

Some differences between the two languages would be as follows:

When printing a value, python 2 treated it as a statement, not requiring any brackets, meaning that a line such as: print “hi!” would suffice. However, print in python 3 became a function, with the contents to be treated placed inside the function to print, such as the line: print(“hi!”,”I am “, name), allowing multiple objects to be printed in python 3, but when used in python 2, the resulting print would be a tuple, or a finite ordered sequence. Another minor key difference is the input function, which in Python 3 is simply “input”, but in Python 2, “raw_input” is the proper keyword to instruct the program to receive user input. As for another function, namely integer division, the “/” command in python 2 will result in an integer, with the program automatically outputting an integer and ignoring the remainder, such as the command “1 / 5” resulting in 0, or “4 / 3” resulting in 1. However, Python 3 carries out proper division, with “1 / 5” resulting in 0.2, or “4 / 3” resulting in 1.3333. If the user wishes to carry out integer division in Python 3, the command “//” is used. True division can also be done in Python 2, however, with the program automatically doing this if one or both of the numbers involved in the division is of a float type (also known as a decimal), such as “1.0 / 5” or “1 / 5.0” resulting in 0.2 if done in Python 2.

There are other methods of using Python as well, such as running it through the command line. In order to do this, “python3” should be entered in the command line, or simply “python” if the user wishes to use the REPL function. The REPL function is similar to that provided by the IDLE program, but without the additional features such as syntax high lights or auto complete, and history can be accessed through the up and down buttons on the keyboard. The user can exit this mode by pressing “control” + “D”.

Another method of using python is to run the IPython command line command. This version of a python development environment has multiple



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.