Python Data Types

Let’s look at data types

  1. Notice

    An object has a type that determines which operations it supports. The name itself is not locked to that type.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
value = 3
print(type(value).__name__)
value = str(value)
print(type(value).__name__)
Live state

Top-level scope

value→Object 2
Object 2 · str'3'
This step

An object has a type that determines which operations it supports. The name itself is not locked to that type.

Picture data types

An object has a type that determines which operations it supports. The name itself is not locked to that type.

Image brief

Alt text
A diagram for Python Data Types. Instructions: value = 3 print(type(value).__name__) value = str(value) print(type(value).__name__). Displayed result: int str. The final example bindings are value --> object 2 (str). object 2: '3'
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python Data Types". Teaching focus: An object has a type that determines which operations it supports. The name itself is not locked to that type. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS value = 3 print(type(value).__name__) value = str(value) print(type(value).__name__) | v DISPLAYED RESULT int str FINAL BINDINGS value --> object 2 (str) object 2: '3' Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python Data Types. Instructions: value = 3 print(type(value).__name__) value = str(value) print(type(value).__name__). Displayed result: int str. The final example bindings are value --> object 2 (str). object 2: '3'

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
value = 3
print(type(value).__name__)
value = str(value)
print(type(value).__name__)
Live state

Top-level scope

value→Object 2
Object 2 · str'3'
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
int
str

What do you expect this program to print?

What does this example display?

value = 3
print(type(value).__name__)
value = str(value)
print(type(value).__name__)
What does this example display?
Choose one answer. You can try again.

Answer and explanation

int str

Follow the printed values in order. The output is: int str

Which explanation matches what you learned?

Which explanation matches what you learned?
Choose one answer. You can try again.

Answer and explanation

An object has a type that determines which operations it supports. The name itself is not locked to that type.

An object has a type that determines which operations it supports. The name itself is not locked to that type.

Data Types

In Python, data comes in different types. Just like in real life, where you have different kinds of things — like numbers, words, and yes/no answers — Python also needs to know what kind of data you're using.

Python uses data types to decide what you can do with the data. For example, you can add two numbers, but you can’t add a number to a word directly.

Common Data Types in Python

Here are some of the most common data types you'll use in Python language:

  • int – whole numbers (like 5, -2, 100)
  • float – decimal numbers (like 3.14, -0.5, 2.0)
  • str – text, also called a “string” (like "Hello", "Python")
  • bool – True or False (used for yes/no decisions)

Example

number = 10           # int
pi = 3.14             # float
name = "Alice"        # str
is_happy = True       # bool

How to Check the Data Type

You can use the type() function to see what kind of data something is:

number = 10           # int
pi = 3.14             # float
name = "Alice"        # str
is_happy = True       # bool

print(type(10))       # <class 'int'>
print(type("Hi"))     # <class 'str'>
print(type(3.5))      # <class 'float'>
print(type(False))    # <class 'bool'>
<class 'int'>
<class 'str'>
<class 'float'>
<class 'bool'>

Conclusion

Every value in Python has a type. Understanding these basic data types will help you store, use, and work with information in your programs.

What to remember

Connect what you noticed in the example with the idea below.

Remember

An object has a type that determines which operations it supports. The name itself is not locked to that type.

Watch out for this idea

A variable must keep the type of its first value.

This is the misconception to avoid.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Python Strings →