WORKING WITH NUMBERS
Python provides arithmetic operations for manipulating numbers a straightforward manner that is similar to other programming languages. The following examples involve arithmetic operations on integers:
>>> 2+2 4 >>> 4/3 1 >>> 3*8 24
The following example assigns numbers to two variables and computes their product:
>>> x = 4 >>> y = 7 >>> x * y 28
The following examples demonstrate arithmetic operations involving integers:
>>> 2+2 4 >>> 4/3 1 >>> 3*8 24
Notice that division (“/”) of two integers is actually truncation in which only the integer result is retained. The following example converts a floating point number into exponential form:
>>> fnum = 0.00012345689000007 >>> "%.14e"%fnum '1.23456890000070e-04'
You can use the int() function and the float() function to convert strings to numbers:
word1 = "123" word2 = "...