Number

You can use integer and floating-point numbers, example:

a = 1
b = 2
print a + b     # 3
print b * 3     # 6
print 1 + 2 * 3 # 7
print (1 + 2) * 3   # 9

c = 1.5
print c * 2     # 3.0

print 1 / 3     # 0
print 1.0 / 3   # 0.333333333333

Conversion between integer and floating-point number:

  • int(x) : convert x to integer
  • long(x) : convert x to long integer
  • float(x) : convert x to floating-point number

Example:

print int(12.3)     # 12
print int("234")    # 234
print long(5.6)     # 5
print float(12)     # 12.0