Why deselecting an already selected vertex does NOT work? I have found out that while it is possible to select vertices by setting select to True, it is not possible to deselect vertices by setting select to False if the vertices are already selected.
Sounds silly but it is not.

To demonstrate this, open a new file with the default cube, switch to Edit mode (all vertices should be selected by default).
Then run this script:

import bpy

bpy.ops.object.mode_set(mode="OBJECT")

bpy.data.meshes['Cube'].vertices[0].select = False

bpy.ops.object.mode_set(mode="EDIT")


The vertex 0 should be deselected, right? Well, it is not.

Now, deselect the top 4 vertices on the Cube and run this:

import bpy

bpy.ops.object.mode_set(mode="OBJECT")

bpy.data.meshes['Cube'].vertices[0].select = False
bpy.data.meshes['Cube'].vertices[5].select = True

bpy.ops.object.mode_set(mode="EDIT")


The vertex 5 will be a new selected one, as it should, but vertex 0 will still be selected but it should not be.

More info: if the select property's value is checked while still in Object mode, it will be False. However, switching to Edit mode makes it back to True.

Why is deselecting vertices not working? Am I missing something?
Actually, yes, you are missing something ;)

The fact is, when you select all vertices of an edge or face, you also select said edge or face (same when you select all edges of a face). In other words, selection of verts, edges and faces are linked together, so if you want to deselect vertices you must first deselect all faces and edges they belong to.

Note that selection operator(s) in editmode take care of that, using current select mode as reference (such that in vertices select mode, deselecting a vertex automatically propagates to relevant edges and faces).