๐ฏ Learning Objectives
By the end of this lesson, learners will be able to:
-
Understand the concept of data types in Python
-
Identify and use basic data types:
str
,int
,float
,bool
-
Use the
type()
function to check data types -
Write code using appropriate data types for different use cases
๐ Lesson Content
๐น What Are Data Types?
In Python, every value has a data type that defines what kind of data it is and what operations can be performed on it.
Pythonโs data types are built-in and automatically detected by the interpreter.
๐ธ 1. String (str
)
Used to represent text. Strings are enclosed in quotes.
You can use single, double, or even triple quotes:
๐ธ 2. Integer (int
)
Represents whole numbers (positive or negative).
๐ธ 3. Float (float
)
Represents decimal numbers or floating-point values.
๐ธ 4. Boolean (bool
)
Represents True or False values.
Booleans are often used in if conditions and logic-based operations.
๐ Using the type()
Function
You can check the data type of any value or variable using type()
.
๐ง Fun Activity
Try this code and guess the data types:
Use type()
on each variable.
๐งฑ Quick Reference Table
Data Type | Example | Function/Purpose |
---|---|---|
str |
"Hello" |
Text strings |
int |
42 |
Whole numbers |
float |
3.14 |
Decimal numbers |
bool |
True/False |
Logical values |
๐ก Real-world Use Examples
-
str
: Usernames, names, messages -
int
: Age, quantity, number of items -
float
: Price, height, temperature -
bool
: Login status, conditions
๐ Assignment
Create four variables with the following:
-
Your full name (string)
-
Your age (integer)
-
Your height (float)
-
Whether you are currently studying Python (boolean)
Use print()
and type()
to display the value and data type of each.