Data Types in Python
Setting the scene
Imagine visiting a library. When you borrow a book, the system records your name (text), the number of books you borrowed (whole number), the price per book if damaged (decimal), and whether the book has been returned (yes or no).
All of this information isn’t the same “type.” A person’s name is text, the count of books is a number, the fine is a decimal, and the return status is a true/false value. That’s why programming languages like Python organize information into data types.
In this lesson, we’ll design a small digital library card that stores different types of information.
Below is a cheat sheet for this lesson, highlighting the key concepts and notes for quick revision.

You’re the programmer who must create digital card. To succeed, you’ll need to understand Python’s data types.
The core idea in Python
A data type tells Python what kind of value a variable holds. Different types of data behave differently when you try to use them.
The four basic types you’ll use most often are:
- String (str): text inside quotes.
Example: "Harry Potter" - Integer (int): whole numbers without decimals.
Example: 5 - Float (float): numbers with decimals.
Example: 3.75 - Boolean (bool): values that are either True or False.
Example in code:
1 2 3 4title = "Harry Potter" # string copies = 3 # integer fine_per_day = 0.50 # float returned = True # boolean
In our library card, each piece of information is a different type:
- A book title must be stored as text (str).
- The number of copies is stored as an integer (int).
- The fine per day is stored as a decimal (float).
- Whether the book has been returned is stored as a boolean (bool).
If we mix up data types, the program won’t behave correctly. For example, you can’t add "3" (a string) to 5 (an integer) without errors.
Quick summary:
- str → for text in quotes
- int → for whole numbers
- float → for decimals
- bool → for True/False
Try it in code
Let’s create a digital card for one student:
1 2 3 4 5 6 7 8 9 10 11student_name = "Ali" book_title = "Python Basics" books_borrowed = 2 fine_per_day = 1.25 returned = False print("Student:", student_name) print("Book:", book_title) print("Borrowed:", books_borrowed) print("Fine per day:", fine_per_day) print("Returned:", returned)
When run, this will show:
1 2 3 4 5Student: Ali Book: Python Basics Borrowed: 2 Fine per day: 1.25 Returned: False
Learn concept with AI
If you’re using an AI assistant, try giving this prompt:
Prompt:
Write a Python program that creates variables for a library card. Include a student name, book title, number of copies, fine per day, and whether the book is returned. Print all details in a neat format.
The AI will generate ready-to-use code with the correct data types.
Excellent work! Now let’s see if you’ve got it.
Task
Create a digital card for a student named Sara, who borrowed the book Data Science 101. She borrowed 3 copies, the fine per day is 2.5, and the books have been returned.
The program should print:
1 2 3 4 5 6=== LIBRARY CARD === Student: Sara Book: Data Science 101 Borrowed: 3 Fine per day: 2.5 Returned: True
Solution
1 2 3 4 5 6 7 8 9 10 11 12student_name = "Sara" book_title = "Data Science 101" books_borrowed = 3 fine_per_day = 2.5 returned = True print("=== LIBRARY CARD ===") print("Student:", student_name) print("Book:", book_title) print("Borrowed:", books_borrowed) print("Fine per day:", fine_per_day) print("Returned:", returned)
Perfect! Now you know how to use Python’s basic data types in real projects.