Press "Enter" to skip to content

Python Example 2 – Numbers in Python

Example #2 Numbers in Python

This post will use a trinket to display the source demoing the use of numbers in Python. The source is commented for context, the output may be seen in the trinket by running it.

Demoing Numbers

*Note: With the trinket widget you may toggle between the code (Pencil icon) and the output (Play button). Please visit my GitHub if you would like to look at all of the Python source code. Laszlo’s GitHub.
**Note: Trinket does not correctly render Classic Division as Python 2 would, rather it renders True Division.

Demoing Numbers with Python 3 Syntax in Python 2

*At the time of this post trinket does not support importing __future__, which allows the use of the explicitly requested feature of Python 3 in Python 2. Bellow is the source example.

#Library Import
from __future__ import division

#We will now see true Division vs Classic Division
print 3/2

By calling the True division from Python 3, the output would be that of 1.5 rather than 1. Classic division will truncate the remainder, the C language implements classic division as well.

Leave a Reply

Your email address will not be published. Required fields are marked *