DocsHub
Basics

Data Types

Learn about the core data types in Python — int, float, str, bool, and None.

Data Types

Every value in Python has a type. The type tells Python what kind of data it is and what you can do with it. You cannot add a number to a sentence, for example — Python needs to know the type to understand what operations make sense.

Python has five core built-in types you will use constantly:

TypeExampleMeaning
int42Whole numbers
float3.14Decimal numbers
str"hello"Text
boolTrueTrue or False
NoneTypeNoneNo value at all

int — whole numbers

An int is any whole number, positive or negative, with no decimal point.

age = 25
score = -10
year = 2024

print(type(age))   # <class 'int'>

Integers in Python have no size limit. You can work with numbers as large as your memory allows — no overflow errors like in some other languages.

big = 999999999999999999999999
print(big + 1)   # works perfectly fine

float — decimal numbers

A float is a number with a decimal point.

price = 9.99
temperature = -3.5
pi = 3.14159

print(type(price))   # <class 'float'>

You can also write floats using scientific notation:

tiny = 1.5e-4    # means 1.5 × 10⁻⁴ = 0.00015
large = 2.5e6    # means 2.5 × 10⁶ = 2500000.0

Floats are not perfectly precise. This is not a Python bug — it is how decimal numbers work in computer memory.

print(0.1 + 0.2)   # 0.30000000000000004

For financial calculations where precision matters, use Python's decimal module instead.


str — text

A str (string) is any sequence of characters wrapped in quotes. You can use single quotes or double quotes — both work the same way.

name = "Ali"
city = 'Lahore'
message = "It's a great day"   # single quote inside double quotes — fine

print(type(name))   # <class 'str'>

For text that spans multiple lines, use triple quotes:

paragraph = """
Python is a great language.
It is easy to read and write.
"""
print(paragraph)

Strings are covered in much more depth in the Data Structures section. For now, just know they hold text.


bool — True or False

A bool has exactly two possible values: True or False. Notice the capital letters — Python is case-sensitive, so true and false will not work.

is_logged_in = True
has_error = False

print(type(is_logged_in))   # <class 'bool'>

Booleans are the result of comparisons:

print(10 > 5)    # True
print(10 == 5)   # False
print(10 != 5)   # True

Under the hood, True is just 1 and False is just 0 in Python. This means you can do arithmetic with them — though you rarely need to:

print(True + True)    # 2
print(False + 1)      # 1

None — no value

None is Python's way of representing the absence of a value. It is not zero, not an empty string — it means nothing at all.

result = None
print(result)          # None
print(type(result))    # <class 'NoneType'>

You will see None in a few common situations:

# A function that returns nothing gives back None
def do_something():
    pass

output = do_something()
print(output)   # None

To check if something is None, use is — not ==:

result = None

if result is None:
    print("No value yet")

is checks if two things are the exact same object in memory. For None, this is the right check because there is only ever one None object in Python.


How Python decides the type

You never declare a type — Python looks at the value and decides:

x = 10        # int   — no decimal point
x = 10.0      # float — has a decimal point
x = "10"      # str   — wrapped in quotes
x = True      # bool  — is True or False
x = None      # NoneType

This means 10, 10.0, and "10" are three completely different things in Python.

print(10 == 10.0)    # True  — same numeric value
print(10 == "10")    # False — number vs string, never equal

Summary

TypeExample valuesUse for
int0, 42, -7Counting, indexing, whole numbers
float3.14, -0.5, 1e10Measurements, decimals, math
str"hello", 'x'Text, names, messages
boolTrue, FalseConditions, flags, on/off states
NoneNoneMissing values, empty results

On this page