Data Types


Written by PIRATE KING

Starting the video will automatically play it from this chapter.

Types in Python

Python has several built-in data types. Data types classify values and determine what operations can be performed on them. When you assign a value to a variable, Python automatically assigns its data type. In this section, we'll explore some common ones.

String

In computer science, text is called a "string" because it represents a sequence—or "string"—of characters arranged in order. This term comes from the idea of characters being linked together like beads on a string. Unlike other data types such as numbers, which represent quantities, strings specifically represent ordered text data. The concept has been part of programming terminology since the 1960s and is now universally used to denote text in code.

For example, assigning full_name = "Pirate King" stores the text (string) "Pirate King" in the variable full_name. When working with text in your programs, remember to enclose it in quotation marks "" (or '').

Numbers

In Python, there are various ways to represent a number. Let's take a look at the most common two.

Integer

In programming, an integer is a whole number that can be positive, negative, or zero. For example, age = 20, net_gain = -1, and zero = 0.

Exercise

Instruction:

Complete the program by declaring a variable named zero, assigning it the value 0, and then printing it.

Expected output:

20
-1
0

Declare the variable zero, assign it the value 0, and then use the print() function to display it.

Execute, and you get 20, -1, and 0.

Float

We can also work with numbers that have decimals. For example, let's create a variable called pi and set it to 3.14. This type of number is called a floating-point number, or float for short. It's a common term you'll hear in almost any programming language. Print it out, run the code, and you'll get 3.14.

Exercise

Instruction:

Declare a variable named pi, assign it the value 3.14, and then print it.

Expected output:

3.14

Floats are numbers with a decimal point. Assign 3.14 to the variable pi and print it using the print() function.

Boolean

A Boolean is a simple data type that can only be one of two values: True or False. The term comes from George Boole, a 19th-century mathematician who created Boolean algebra. It's used to represent yes/no, on/off, or any condition that can have just two possible answers. For example, you can use booleans to check if something is true or false and control how your program runs based on that. Here, we have is_logged_in set to True.

Exercise

Instruction:

Assign the value False to a variable called is_asia, then display its value using the print() function.

Expected output:

True
False

Assign False to the variable is_asia and use the print() function to display it.

Run this and you get True and False. These are Python's Boolean values. Remember, Python is case sensitive — so Booleans must always start with a capital letter. Writing false or FALSE won't work; only True and False are valid Boolean values in Python.

Run this and you get a NameError.

Pro Tip: Notice how the editor didn't color "FALSE" or "true" in blue. This is a another indicator that the Boolean syntax is incorrect.

None

In Python, None is a special value that means "no value" or "nothing." It's its own data type called NoneType. You'll often see None used when a function doesn't return anything, or as a placeholder when you want to indicate the absence of a value. It's different from 0, False, or an empty string ""None simply means no value at all.

Exercise

Instruction:

Assign the value None to a variable called no_value, then display its value using the print() function.

Expected output:

None

The None keyword is case-sensitive. Assign it to the variable no_value.

Type Function

That wraps up the common data types in Python. Before moving on, let me quickly introduce a handy function. Remember how Python automatically sets a variable's data type based on its value? Let's check that with this function.

type()

The type() function in Python tells you the data type of any object or value. Just pass the value or variable to type(), and it will return its class, like 'int' for numbers or 'str' for text. Let's check it out.

Exercise

Instruction:

Complete the program to match the expected output:
- Assign any whole number to the variable age.
- Print the data type of the variable name for the str type.
- Print the data type of the any Boolean for the bool type.

Expected output:

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

Pass a variable or value into the type() function and wrap it with print() to see the result in the terminal.

We'll learn about classes later. The key takeaway is that type() is a handy way to check what kind of data you're working with.

Other Built-in Types

Those are the basic Python data types. There are many more to explore, but here's a quick example list:
  • list for ordered, mutable collections of items
  • tuple for ordered, immutable collections of items
  • range for sequence of numbers, often used for looping
  • dict for dictionaries or collections of key-value pairs
  • set for collections of unique items
  • complex for complex numbers
  • bytes for sequence of bytes
And more!

Quiz

1. Which of the following correctly defines a string in Python?

2. Select ALL valid Python data types from the list:

3. Python Boolean values must start with uppercase letters (True, False). The lowercase forms true and false are invalid.

4. What does the keyword None represent in Python?

5. Write a Python program that:

  • Declares a variable boolean_expression that stores the result of the expression 10 > 5
  • Prints the value and type of boolean_expression

Expected output:

True
<class 'bool'>

You can store the result of a comparison 10 > 5 directly in a variable. Use the type() function within a print() statement to display the class name.

© PIRATE KING 2026
GOLDSTONE STUDIO LLC
Privacy Policy