Python Basics · Lesson 3
Python Data Types
Learn how Python classifies values as integers, floating-point numbers, strings and booleans, and how to identify a value's data type using type().
What you will learn
- • What a data type is
- • Integers — int
- • Floating-point numbers — float
- • Strings — str
- • Boolean values — bool
- • Using type()
- • Identifying data types
- • Common type mistakes
Part 1
What is a data type?
A data type tells Python what kind of value it is working with. Different kinds of values can behave differently in a program.
25Integer
25.5Float
"25"String
TrueBoolean
CHECK YOUR UNDERSTANDING
What does a data type tell Python?
Part 2
Integers — int
Integers are whole numbers without a decimal part. They can be positive, negative or zero.
age = 25
students = 100
temperature = -5
score = 0CHECK YOUR UNDERSTANDING
Which value is an integer?
CHECK YOUR UNDERSTANDING
Which value is also an integer?
Part 3
Floating-point numbers — float
A float represents a number containing a decimal component.
price = 99.99
height = 1.75
average = 82.5CHECK YOUR UNDERSTANDING
Which value is a float?
CHECK YOUR UNDERSTANDING
Which variable contains a float?
Part 4
Strings — str
A string is text. Strings are commonly written inside single or double quotation marks.
"Python"'Vista Academy'CHECK YOUR UNDERSTANDING
Which value is a string?
CHECK YOUR UNDERSTANDING
What is the data type of "100"?
Part 5
Boolean values — bool
Boolean values represent one of two states: True or False. Booleans are especially useful when programs need to make decisions.
is_student = True
is_logged_in = FalseCHECK YOUR UNDERSTANDING
Which value is a Boolean?
CHECK YOUR UNDERSTANDING
Which statement stores a Boolean value?
Part 6
Finding a data type with type()
Python provides the type() function to inspect the data type of a value.
age = 25
print(type(age))CHECK YOUR UNDERSTANDING
What does type(age) help you find?
CHECK YOUR UNDERSTANDING
What is the type of "Python"?
CHECK YOUR UNDERSTANDING
What is the type of 25?
CHECK YOUR UNDERSTANDING
What is the type of 25.5?
Predict the output
Can you identify the value?
x = "25"
print(x)CHECK YOUR UNDERSTANDING
What will print(x) display?
Same-looking values can have different types
a = 10
b = "10"
print(type(a))
print(type(b))CHECK YOUR UNDERSTANDING
How are a and b different?
Your turn
Complete the answers
The data type of 100 is _____.
The data type of 10.5 is _____.
The data type of "Python" is _____.
The data type of True is _____.
Debug the type mistake
age = "25"
result = age + 5CHECK YOUR UNDERSTANDING
Why can this code cause a type error?
Mini Challenge
Build a data profile
Create four variables representing a person's name, age, height and student status. Use an appropriate data type for each.
name = "Aman"
age = 21
height = 1.75
is_student = TrueFinal Challenge
Create and inspect your own variables
Create one integer, one float, one string and one Boolean variable. Then use type() to inspect each one.
age = 25
price = 99.99
name = "Yogesh"
is_student = True
print(type(age))
print(type(price))
print(type(name))
print(type(is_student))Lesson recap
- ✓ Data types describe the kind of value being used.
- ✓ int represents whole numbers.
- ✓ float represents decimal numbers.
- ✓ str represents text.
- ✓ bool represents True or False.
- ✓ type() can be used to inspect a value's type.
- ✓ Similar-looking values can have different data types.
- ✓ Understanding types helps prevent programming errors.