Worked Examples · Example 5.3
Q.Example 5.3:
num1 = 10
type(num1)
<class 'int'>
num2 = -1210
type(num2)
<class 'int'>
var1 = True
type(var1)
<class 'bool'>
float1 = -1921.9
type(float1)
<class 'float'>
float2 = -9.8*10**2
print(float2, type(float2))
-980.0000000000001 <class 'float'>
var2 = -3+7.2j
print(var2, type(var2))
(-3+7.2j) <class 'complex'>
num1 = 10
type(num1)
<class 'int'>
num2 = -1210
type(num2)
<class 'int'>
var1 = True
type(var1)
<class 'bool'>
float1 = -1921.9
type(float1)
<class 'float'>
float2 = -9.8*10**2
print(float2, type(float2))
-980.0000000000001 <class 'float'>
var2 = -3+7.2j
print(var2, type(var2))
(-3+7.2j) <class 'complex'>
Karnataka PUCTextbookSubjective· 3mImportance★★★★★est
10% · 5/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →type() identifies a value's data type — the example walks through int, bool, float and complex, and shows the floating-point quirk where −9.8*10**2 prints as −980.0000000000001.
The concept: every Python value is an object of some class (type), and type() tells you which. Knowing the type matters because it decides what operations are legal and how results behave (e.g. / versus //).
>>> num1 = 10
>>> type(num1)
<class 'int'>
>>> num2 = -1210
>>> type(num2)
<class 'int'>
>>> var1 = True
>>> type(var1)
<class 'bool'>
>>> float1 = -1921.9
>>> type(float1)
<class 'float'>
>>> float2 = -9.8*10**2
>>> print(float2, type(float2))
-980.0000000000001 <class 'float'>
>>> var2 = -3+7.2j
>>> print(var2, type(var2))
(-3+7.2j) <class 'complex'>
Walking through it:
- int — whole numbers of any size, positive or negative (10, −1210).
- bool — the two truth values True and False form their own class (bool is in fact a subclass of int, with True behaving as 1).
- float — numbers with a fractional part (−1921.9). The interesting line is
-9.8*10**2: mathematically −980 exactly, but 9.8 cannot be represented exactly in binary, so the computed float is −980.0000000000001. This is not a Python bug — it is how binary floating point works in every language. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.