Python types Module
Example
Create a simple namespace object:
import types
ns = types.SimpleNamespace(name='Tobias', age=28)
print(f'Name: {ns.name}, Age: {ns.age}')
Try it Yourself »
Definition and Usage
The types module defines names for built-in types and provides utility functions for creating new types.
Use it to check object types, create dynamic types, or work with Python's type system programmatically.
Members
Member | Description |
---|---|
FunctionType | Type of user-defined functions. |
GeneratorType | Type of generator objects. |
LambdaType | Type of lambda functions. |
MethodType | Type of bound methods. |
ModuleType | Type of modules. |
SimpleNamespace | Simple class for creating objects with attributes. |
TracebackType | Type of traceback objects. |
new_class() | Create a class dynamically. |
prepare_class() | Calculate metaclass and namespace for class creation. |