
Learning outcomes
By the end of this chapter, you should be able to:- explain
int,float,bool, andstr - check data types using
type() - convert values safely between basic types
What is a data type?
A data type defines:- kind of value stored
- operations allowed on that value
Core scalar types
int
Whole numbers, positive or negative.
float
Decimal numbers.
bool
Logical values True and False.
str
Text data.
Checking type
Type conversion
int(float("2.5")) if needed.
Type conversion and boolean
Exam-focused points
type()returns class/type of object- invalid conversion raises
ValueError boolis a subclass of integer in Python behavior (True == 1,False == 0)
Practice questions
- Predict type and output:
- Take a decimal input and print integer part.
- Write examples where conversion fails and explain why.
