Operations with different types#

When you combine types in an expression, Python will try to do what it thinks is the most sensible thing. Let’s explore this:

1 is an integer. 2 is an integer.

Exercise What is the type of 1/2? .

Exercise What is the type of 1 // 2 and 1 % 2

Exercise What is the type of 5.0 * 2? Is that the same type as 5 * 2

The complex number type#

There’s also a complex type, which are made in the form 1+2j or 0.5-0.3j where j is defined as the square-root of -1 (normally written in maths/physics as i). (If complex numbers doesn’t mean anything to you now, don’t worry. It will do soon, and this could very well be useful in the future!)

Exercise What is the type of 1 + 2j?

1 + 2j
(1+2j)