How to set any material via python

Hello I want to change the material of some objects, since it is not applied the material, I want you to apply via code in python, is a group of three materials that is just an object, I want wif the cube gets a material a sphere with another material different from the cube, and a cone with another material different from the sphere and cube.

• creating and assigning materials is covered here If you are using cycles then adding nodes to a material is also covered here Jan 18 '16 at 9:03
• This question could be clearer. Your other question was about doing Booleans and I'd like to know if this question is a continuation of that. Do you mean you want to preserve the unique materials after doing a Boolean? so the resulting object (after boolean) has several materials given by the surfaces of the objects involved in the booleans? Jan 18 '16 at 9:52
• do you mean this kind of material assignment? : i.stack.imgur.com/V0iBe.png Jan 18 '16 at 10:00

import bpy