What are the basic data types in Python?

· Category: Python Programming

Short answer

Python provides several built-in basic data types: int for integers, float for decimal numbers, str for text, bool for Boolean values (True/False), and NoneType for the absence of a value.

How it works

  • int: Arbitrary-precision integers (no overflow limit in standard use).
  • float: IEEE 754 double-precision floating-point numbers.
  • str: Immutable sequences of Unicode characters.
  • bool: A subclass of int where True == 1 and False == 0.
  • NoneType: The type of the singleton None, often used as a default or placeholder.
# Basic types
count = 10                # int
price = 19.99             # float
label = "Active"          # str
is_valid = True           # bool
result = None             # NoneType

# Checking types
print(type(count))        # <class 'int'>
print(type(price))        # <class 'float'>
print(isinstance(label, str))  # True

Example

Converting between types is common when reading user input or parsing data:

user_input = "42"
number = int(user_input)
floating = float("3.14")
text = str(100)
print(number, floating, text)

Why it matters

Understanding basic types prevents bugs caused by implicit conversions and helps you choose the right structure for your data. For example, using float for money calculations can introduce rounding errors, which is why decimal.Decimal exists for financial applications.