Skip to main content

Types

  • Types

Built-in Types

Python has several built-in types, including:

  • Numeric Types: int, float, complex
  • Sequence Types: list, tuple, range
  • Text Type: str
  • Set Types: set, frozenset
  • Mapping Type: dict
  • Boolean Type: bool
  • Binary Types: bytes, bytearray, memoryview
  • None Type: NoneType

Examples

# Numeric Types
integer = 10
floating_point = 10.5
complex_number = 1 + 2j

# Sequence Types
list_example = [1, 2, 3]
tuple_example = (1, 2, 3)
range_example = range(1, 10)

# Text Type
string_example = "Hello, World!"

# Set Types
set_example = {1, 2, 3}
frozenset_example = frozenset([1, 2, 3])

# Mapping Type
dict_example = {"key": "value"}

# Boolean Type
bool_example = True

# Binary Types
bytes_example = b"Hello"
bytearray_example = bytearray(5)
memoryview_example = memoryview(bytes(5))

# None Type
none_example = None

Type conversion

int()
float()
str()

x = 5
y = float(x)
binary = bytes("hi", "utf-8")

# ver o tipo
type(x)

Constants

PI = 3.14159