Game Development Reference
In-Depth Information
A - Differences Between Python 2 and 3
>>> listOfInts = list(range(10))
Division with the / Operator
In Python 2, doing division with the / operator results in a floating point number (that is,
a number with a decimal point) only if one of the numbers is a float itself:
>>> # Python 2
>>> 25.0 / 8
3.125
>>> 25 / 8.0
3.125
However, in Python 2, if both of the numbers are integers, then the result of division is
the rounded down integer. In Python 3, the result is a floating point number no matter what:
>>> # Python 2
>>> 25 / 8
3
>>> # Python 3
>>> 25 / 8
3.125
Formatting Strings with the format() Method and
%s
In both Python 2 and 3, you can include %s inside a string and follow it with a list of
values for each %s such as:
>>> # Python 2 and 3
>>> 'My name is %s and I am from %s.' % ('Al',
'Houston')
'My name is Al and I am from Houston.'
However, Python 3 adds a new string method called format() . This string lets you
provide a list of arguments as parameters to format(). Instead of %s, you use {0} and {1}
and {2} and so on:
Search WWH ::




Custom Search