Python 2.8 - how to assign a material in shading versus layout workspace
The following script allows you to create a material with the colors you'd like and assign it to a specific object. The material is only created once, if another material with the same name already exists that one is used. If it finds the expected shader node it sets the desired color. The first argument is the object you want the material assigned to, which can be retrieved e.g. through bpy.data.objects['NameOfYourObjectHere'].

def add_material(obj, material_name, r, g, b):
    material = bpy.data.materials.get(material_name)

    if material is None:
        material = bpy.data.materials.new(material_name)

    material.use_nodes = True
    principled_bsdf = material.node_tree.nodes.get('Principled BSDF')

    if principled_bsdf is not None:
        principled_bsdf.inputs[0].default_value = (r, g, b, 1)  

    obj.active_material = material