How to add a color to a generated cube within a python script
Objects still have a color (as indicated in the documentation).
Though, bpy.ops does not return what is created or done by the ops, but the result state of the operation.
if you print(obj)in your code, you should see {'FINISHED'}.
What you can do using ops is:
import bpy 

bpy.ops.mesh.primitive_cube_add() 
obj = bpy.context.object
obj.color = (0,0,1,1)

Because the operation links the object to the context.
So, this work, but the color won't be rendered except in workbench rendering. It is also visible in solid view when object is selected here:

To set this color to the material, you can complete the script by the following:
import bpy 

bpy.ops.mesh.primitive_cube_add() 

obj = bpy.context.object

obj.color = (0,0,1,1)


# Create a material
mat = bpy.data.materials.new(&quot;Blue&quot;)

# Activate its nodes
mat.use_nodes = True

# Get the principled BSDF (created by default)
principled = mat.node_tree.nodes['Principled BSDF']

# Assign the color
principled.inputs['Base Color'].default_value = (0,0,1,1)

# Assign the material to the object
obj.data.materials.append(mat)