Which of the following is an example of an integer in Python?
A
3.0 B
'3' C
3 D
3 + 0j
Analysis & Theory
`3` is an integer. `3.0` is a float, `'3'` is a string, and `3 + 0j` is a complex number.
What is the type of `3.14` in Python?
A
<class 'int'> B
<class 'float'> C
<class 'complex'> D
<class 'str'>
Analysis & Theory
`3.14` is a floating-point number, so its type is `float`.
Which of these represents a complex number in Python?
A
5 + 6j B
5 + 6i C
5 + j D
complex(5 + i)
Analysis & Theory
In Python, complex numbers use `j` as the imaginary unit, like `5 + 6j`.
What is the result of `type(5 // 2)`?
A
<class 'float'> B
<class 'int'> C
<class 'complex'> D
<class 'bool'>
Analysis & Theory
`//` is floor division and always returns an integer if both operands are integers.
Which operation will result in a float?
A
7 / 2 B
7 // 2 C
int(7 / 2) D
7 % 2
Analysis & Theory
`/` always returns a float in Python, even if dividing two integers.
Which function returns the absolute value of a number in Python?
A
abs() B
fabs() C
mod() D
math.abs()
Analysis & Theory
`abs()` is a built-in function that returns the absolute value of a number.
What will `int(4.9)` return?
A
4.9 B
5 C
4 D
Error
Analysis & Theory
`int()` truncates the decimal part and returns only the integer portion.
Which function can be used to convert an integer to a float?
A
int() B
float() C
str() D
bool()
Analysis & Theory
`float()` converts integers to floating-point numbers.
What is the result of `round(5.6)`?
A
5 B
6 C
5.0 D
5.5
Analysis & Theory
`round(5.6)` rounds the number to the nearest integer, which is `6`.
What is the type of the result of `3 + 4j`?
A
<class 'float'> B
<class 'int'> C
<class 'complex'> D
<class 'str'>
Analysis & Theory
`3 + 4j` is a complex number, so its type is `<class 'complex'>`.