Python: Assign selected faces to vertex group
You have missing &quot;bpy&quot; on line 4, so it should be:
group = bpy.context.object.vertex_groups.new()

Don't forget to import bpy:
import bpy

Whole script:
import bpy
sub2 = 0
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.mesh.select_random(percent=55, seed=10, action='DESELECT')
bpy.ops.mesh.split()    
group = bpy.context.object.vertex_groups.new()
group.name = (&quot;Island&quot; + str(sub2))
#group.add(bpy.data.objects.data.verts, 1.0, 'ADD')
bpy.ops.object.vertex_group_assign()