A programmer writes the following code: `x = 7` then `y = 2` then `z = x / y`. What is the data type and value of `z`?
In Python 3, the `/` operator performs true division and always returns a `float`, regardless of operand types. With `x = 7` and `y = 2`, the result is `3.5`, a floating-point number. This is a key difference from Python 2, where integer division with `/` would yield an integer. Here, the type is `float` and the value is `3.5`.
Why this answer
In Python 3, the division operator `/` always returns a float, even when dividing two integers that yield a whole number. For `x = 7` and `y = 2`, the result is `3.5`, stored as a `float`. This behavior differs from Python 2, where `/` performed integer division for integers.
The `//` operator performs floor division and returns an integer when both operands are integers, but that is not used here.
Exam trap
The trap here is assuming that division of two integers returns an integer, perhaps due to experience with other programming languages or Python 2.