bhylu.com

Advertisements

Data Types

A value's type determines the operations it supports. Learn to ask what a value means before converting it or combining it with another value.

Understand the idea

Whole numbers use int, fractional binary values use float, text uses str, and logical values use bool. Containers such as lists and dictionaries hold related objects. type can help inspect unfamiliar inputs, but application design should define expected input shapes rather than scatter guesses about types throughout the code.

Where to try it

Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.

A worked example

Python

values = [12, 2.5, "12", True, None]
for value in values:
    print(type(value).__name__)

Read the result

The printed types are int, float, str, bool, and NoneType. The quoted digits are text even though they look like a number.

Try one change

Create a dictionary containing a workshop name, seat count, and open flag. Describe the role of each type.