The class and the def commands each create an object and bind a local name to it. In the first instance, class creates a class object and binds the name Main to it. In the second instance, def creates a code object and binds the name Main to it.
The name Main is bound to two objects in turn. First, to a class object and next to a code object. This is nearly identical to what happens when a variable is assigned. Consider this code snippet:
Main = 'foo'
Main = 1 + 2
In the first line, the interpreter creates* a str object and binds the name Main to it. In the second line, the interpreter creates* an int object and binds the name Main to it.
So the case of having a class definitioon followed by a similarly-named function definition is identical to the case of multiple assignments. Specifically, the name continues to be bound to whatever object it was bound to most recently. (Either a code object or 3, in the examples above.)
If the previous object no longer has any references, then it is subject to deletion and garbage collection. Precisely how it is deleted and/or collected is an implementation detail that need not concern us.
*The assignment operations above might not create the object on the right-hand side. If 'foo' or 3 already exists, then it might be re-used. See "immutable objects" and/or "string interning" for more info.
References: