Type

Type is a collection of rules for constructs such as variables and functions. Untyped languages allow any operation to be performed on any data type.

Static vs. Dynamic

  • static:  type is set during compile

  • dynamic: type is set during execution

Strong vs. Weak

  • strong: type cannot change during execution

  • weak: type can change during execution

Language Examples

Python Example

Details on Python types can be found here.

Main Python types include:

  • numerics

    • int

    • float

    • complex

  • sequences

    • list - mutable, defined with [ ]

    • tuple - immutable, defined with ( )

    • range - defined with range( )

    • str - define with “ “ or ‘ ‘

    • binary

      • bytes

      • bytearray

  • mappings

    • dict - defined with { }

  • classes

  • instances

  • exceptions

# An example of a type() function return value is: <type 'str'>

# Determine the type of a variable.
variable_example = "A test string."
variable_type = type(variable_example)
print(variable_type)