Create your own
Lesson illustration

Classifying Data Types with Literals and `type()`

Hello again. In the previous lesson, you learned that variables are names that hold values and that assignment can replace or update a value as a program runs. But values are not all the same kind of thing. Python needs to know whether a value is a count, a decimal measurement, text, or a true/false state so it can handle it correctly.

This lesson introduces four core Python data types:

  • integers: whole numbers
  • floating-point numbers: decimal numbers
  • strings: text
  • Booleans: True or False

You will learn to recognize their literals—values written directly in code—and verify Python’s classification with type().


A value has both content and a type

A data type describes what kind of value something is. Compare these three values:

7
7.0
"7"

They may look related to a person, but Python treats them as different types:

  • 7 is a whole number.
  • 7.0 is a decimal number.
  • "7" is text because quotation marks surround it.

A value written directly in a program is called a literal. These are all literals:

42
3.14
"Python"
True

When you assign a literal to a variable, the variable refers to a value of that type:

book_count = 4
reading_time = 25.5
book_title = "The Left Hand of Darkness"
is_finished = False

For now, think of the variable’s type as coming from the value placed into it.

Python has many data types, but these four appear constantly and form the foundation for the programs you will write in the next several modules.


Integers: whole numbers

An integer, abbreviated by Python as int, is a whole number with no decimal point.

days_in_week = 7
score = 120
temperature = -3
empty_count = 0

All four values are integers:

7
120
-3
0

Integers are appropriate for quantities that normally come in complete units:

  • number of books on a shelf
  • number of completed lessons
  • points in a game
  • a year, such as 2026
  • a temperature when only whole degrees are being recorded

The sign does not change the type. Both 15 and -15 are integers.

Do not confuse an integer with text that happens to contain digits:

lesson_number = 5
lesson_code = "5"

lesson_number stores an integer. lesson_code stores a string. The quotation marks make the difference.


Floats: numbers written with a decimal point

A floating-point number, usually called a float, is a numeric value written with a decimal point.

price = 12.99
distance_km = 4.5
temperature = -2.75
completion_rate = 1.0

Each value above is a float. Even 1.0 is a float, not an integer, because of the decimal point.

This distinction matters:

whole_hours = 2
measured_hours = 2.0

Both represent the same quantity to a human, but Python classifies the first as int and the second as float.

Use floats for values where a fractional amount makes sense:

  • a price such as 8.50
  • a weight such as 1.25
  • a distance such as 3.7
  • a measurement such as 21.6
  • an average such as 87.5

For this course, a useful rule is:

Written valueType
8integer (int)
8.0float (float)
-8integer (int)
-8.0float (float)

You will use integers and floats in arithmetic next. At this stage, focus on recognizing that the presence of a decimal point makes a numeric literal a float.


Strings: text enclosed in quotation marks

A string, abbreviated str, is a sequence of characters used to represent text. In Python, you create a string by placing quotation marks around it.

name = "Mina"
course = 'Python'
message = "Welcome to lesson 4."

Python accepts either double quotes or single quotes:

"hello"
'hello'

Both are strings. Pick one style and use it consistently when possible; double quotes will be used most often in this course.

A string can contain letters, spaces, punctuation, symbols, and digits:

email = "mina42@example.com"
address = "14 Oak Street"
pin_text = "0042"

The value "0042" looks numeric, but it is text. Python does not treat quotation marks as part of the stored text; they are markers that tell Python where the string begins and ends.

This is an especially important contrast:

pages_read = 42
pages_read_text = "42"

The first value is a number that will be suitable for calculations. The second is text. Python will not automatically treat "42" as the number 42.

You will work much more deeply with strings in the next module. For now, the reliable recognition rule is simple:

If text is surrounded by matching single or double quotation marks, it is a string.


Booleans: values with two possible states

A Boolean, abbreviated bool, represents a value with exactly two possibilities:

True
False

The spelling matters. Python requires a capital T in True and a capital F in False.

is_logged_in = True
has_finished_lesson = False
is_available = True

Boolean variables often have names that read like a yes-or-no question:

is_raining = False
has_access = True
game_over = False

At this point, you can think of Booleans as clear statements of state:

SituationBoolean value
A task has been completedTrue
A task has not been completedFalse
An item is availableTrue
An account is inactiveFalse

The following are not Booleans:

"True"
"False"
true
false

"True" and "False" are strings because they have quotation marks. Lowercase true and false are not the built-in Boolean literals Python recognizes.

Booleans will become central when you write decisions with if statements later. A program will be able to check a condition and choose different actions depending on whether its result is True or False.


Verify a type with type()

Visual clues are useful, but Python can tell you a value’s actual type directly. The built-in type() function inspects a value or variable.

Try these statements in your browser-based Python workspace:

print(type(12))
print(type(12.0))
print(type("12"))
print(type(True))

The output will look like this:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>

The word after class is the part to focus on:

ExpressionImportant resultMeaning
type(12)intinteger
type(12.0)floatfloating-point number
type("12")strstring
type(True)boolBoolean

For now, read <class 'int'> as “Python says this is an integer.” You do not need to understand the technical meaning of class yet.

You can also inspect a variable. This is often more useful because real programs store values under names:

daily_goal = 30
progress_percent = 62.5
learner_name = "Sam"
is_on_schedule = True

print(type(daily_goal))
print(type(progress_percent))
print(type(learner_name))
print(type(is_on_schedule))

Notice that type() receives the variable name without quotation marks. It examines the value stored in that variable.

Compare:

status = True

print(type(status))
print(type("status"))

Output:

<class 'bool'>
<class 'str'>

The first call checks the value held by status, which is True. The second call checks the text "status" itself, which is a string.

Watch this short demonstration from GeoDelta Labs before moving to the hands-on program. It shows both the literal forms and the type() results in a Python shell.

Lesson 4- Basic Data Types in Python (int, float, str, bool)

In “Lesson 4 – Basic Data Types in Python,” GeoDelta Labs introduces the four types and then verifies each one with type(). Watch it to reinforce the visual difference between values such as 1, 1.0, "1", and True.

Watch the four types for the definitions and examples of integers, floats, strings, and Booleans. Then watch type checks to see each type inspected in the Python shell. Pay particular attention to the difference between a number with a decimal point and one without, and to the quotation marks around strings.


Build a type inspector

Create a new Python file in your browser workspace, or replace the contents of main.py, with this program:

completed_lessons = 3
study_minutes = 27.5
current_topic = "Python data types"
is_practice_day = True

print("Learning dashboard")
print("")

print("Completed lessons:", completed_lessons)
print("Type:", type(completed_lessons))
print("")

print("Study minutes:", study_minutes)
print("Type:", type(study_minutes))
print("")

print("Current topic:", current_topic)
print("Type:", type(current_topic))
print("")

print("Practice day:", is_practice_day)
print("Type:", type(is_practice_day))

Run it. Your exact displayed values may differ after you customize it, but the type labels should be:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'bool'>

This program follows a useful pattern:

  1. Store a value in a descriptive variable.
  2. Print the value so a person can read it.
  3. Use type() to let Python report its category.

Now deliberately change one value at a time and run the program again:

completed_lessons = 3.0

The type changes from int to float.

Next, try:

is_practice_day = "True"

The displayed type changes from bool to str. Although the text looks like a Boolean value, the quotation marks make it a string.

Finally, change this line:

current_topic = 2026

It is valid Python, and type(current_topic) will report int. However, the name current_topic suggests that it should store text. Good programs keep variable names and value types aligned with their meaning.


A quick classification routine

When you encounter a simple Python literal, classify it in this order:

  1. Are there quotation marks?
    If yes, it is a string: "False", "19.99", and "hello" are all str.

  2. Is it exactly True or False, without quotation marks?
    If yes, it is a Boolean: bool.

  3. Is it a number with a decimal point?
    If yes, it is a float: 5.0, -1.5, and 0.25.

  4. Is it a whole number without a decimal point?
    Then it is an integer: 0, 15, and -9.

When a case is unclear, do not guess. Put it into type().

print(type("3.0"))

Python reports str, because quotes are the decisive clue.


Key takeaways

The four core types introduced here are:

  • int for whole numbers, such as 8 and -2
  • float for numbers written with decimal points, such as 8.0 and 3.75
  • str for text in quotation marks, such as "8" and "Hello"
  • bool for the two logical values True and False

A literal is a value written directly in code. The same characters can describe different values depending on their form: 8, 8.0, and "8" are three different types.

Use type(value) or type(variable_name) whenever you need Python to identify a type rather than relying on appearance.

Next, you will use integers and floats in arithmetic expressions, learning how Python evaluates calculations and how operator precedence affects the result.

Can't find a good explanation? Sign up and we'll make it for you

Sign up