Learning Python

Working with numbers

  • int
  • float
  • complex

The basics about numbers

def main:
    q = -1
    x = 1
    y = 3.14
    z = 1j
    print(type(q))
    print(type(x))
    print(type(y))
    print(type(z))
<class 'int'>
<class 'int'>
<class 'float'>
<class 'complex'>

Type conversion

Complex numbers cannot be converted into another number type

def main:
    x = 1
    y = 3.14
    z = 1j

    a = float(x)
    b = float(y)

    print(a)
    print(b)

    print(type(a))
    print(type(b))