Context managers are used with the 'with' statement to manage resources, such as file handling or database connections, ensuring proper cleanup.