How to set the newly added material to an object as "active" (or selected) material
To select the last appended material (which corresponds to a material slot in the UI), you can set active material index:

import bpy

ob = bpy.context.active_object
mat = bpy.data.materials.new(name="Example Material")
ob.data.materials.append(mat)

# As appended the new material slot index is len - 1
ob.active_material_index = len(ob.material_slots) - 1