Here is a general fact (due to a bunch of people in the late 60s, early 70s):
A connected space is (weakly equivalent to) an infinite loop space if
and only if it admits an action of an $E_\infty$-operad.
Let me try to unpack this statement. An $E_\infty$-operad $\mathcal{O}$, first of all, is an operad all of whose spaces $\mathcal{O}(n)$ are contractible.
(Sometimes also want to require that the action of the symmetric group on $\mathcal{O}(n)$ be free; this is important if you want the theory of $E_\infty$-algebras to be homotopy invariant. For instance, if you take your $E_\infty$-operad to consist of a point in each dimension, then sure, an algebra over that operad -- that is, a topological abelian group -- is an infinite loop space -- but those algebras tend not to be interesting, and certainly don't model all infinite loop spaces. Note that topological abelian groups are always weakly equivalent to infinite products of Eilenberg-MacLane spaces.)
Now being an algebra over an $E_\infty$-operad is a way of saying that your space is as close to a commutative monoid as possible. That is, there's a multiplication law (pick any point in $\mathcal{O}(2)$ to get a map $m: X^2 \to X$), it's homotopy associative (that's because the two $m(m(\cdot, \cdot), \cdot), m(\cdot, m(\cdot, \cdot))$ are both 3-ary operations coming from $\mathcal{O}(3)$, which is contractible). Moreover, there are higher coherence homotopies (infinitely many) which are conveniently packaged in the operad: that's one of the things operads do efficiently!
One example of a coherence condition is the following. So we know that $m(x, m(y, (m(z, w)))$ and $m(m(m(x, y), z), w)$ are both canonically homotopic (as maps from $X^4 \to X$). But there are two different ways we could make the homotopy go. We want a coherence homotopy between those two homotopies. This is the analog of the MacLane coherence axioms on a monoidal category; you want the various iterated identifications one can make between iterated multiplication laws to be all homotopic.
I'll also mention a weaker (and easier) result:
A connected space is (weakly equivalent to) a loop space if and only if it admits an action of an $A_\infty$-operad.
An algebra over $A_\infty$-operad is something which is supposed to be as close to associative as possible. The standard example is the little intervals operad. If you take $\mathcal{O}(n)$ to consist of the space of imbeddings of $n$ intervals in the interval, then that acts on $\Omega X$ for any $X$. (How? Use these embeddings to compose a bunch of loops.) The point is that being an $A_\infty$-space, rather than simply a homotopy associative H space, is the data you need to construct a classifying space. (The whole story essentially begins with the theory of classifying spaces; it's what shows you that any topological group $G$ is the loop space on $BG$.) You can do this either by first strictifying your $A_\infty$-space into an actual topological monoid (yes, you can do this, essentially because the associatve operad is still "reasonable" insofar as it is acted on freely by the symmetric group; Berger and Moerdijk's paper on homotopy theory for operads), and then take the usual classifying space. Or you can do it directly, e.g. as Segal does it in the paper I mention below.
The result for $E_\infty$-operads and infinite loop spaces is supposed to be more or less the following: take iterated classifying spaces. I don't think that's how May does it (though I don't understand May's construction that well at the moment), but apparently Boardman and Vogt prove it that way.
A very intuitive and fun paper on this sort of thing is Segal's "Categories and cohomology theories." Segal introduces his own form of delooping machinery, which in fact implies the result about $A_\infty$-spaces that I described above.
Finally, let me say something about exactly how
$E_\infty$ spaces are like abelian groups. There is a general theory of algebras and commutative algebras in a monoidal $\infty$-category, due to Lurie (developed in DAG II and III, now in "Higher Algebra"). The definition works out so that "commutative algebra" really means "homotopy commutative algebra up to infinitely many higher homotopies" (as it always does in $\infty$-land). So an associative algebra object in spaces is an $A_\infty$-space, and a commutative algebra object is an $E_\infty$-space. I think one of the motivations of higher category theory is to say efficiently what "up to coherent homotopy" means. For instance, you can think of an $\infty$-category as a "topological category where multiplication is associative up to coherent homotopy."
Here's an illustrated version of Sharkos' answer. We'll use the disk model of ℝP2: consider a disk with antipodal points on its boundary identified.
We can imagine a closed path that starts at the center, goes straight up (1st part in light blue) hits the topmost point of the disk's boundary - which is also the lowermost point of the disk's boundary - and then continues upwards (now from the bottom, 2nd part in dark blue) to reach the center again and close the loop:
We cannot shrink this loop to a point: we can modify it within the interior of the disk, but that doesn't get us very far. And if we try to change the loop at the point it crosses the boundary, we have to move the top and the bottom of the loop so that they cross at antipodal points, otherwise we brake the loop. For instance, doing the following breaks the loop:
We can slide both points so they stay opposite each other:
But that doesn't allow us to shrink this loop to a point.
Next we consider a loop that crosses the boundary twice:
The loops starts from the center, goes straight up to the top of the disk (1st part in light blue), comes up from the bottom to the center (2nd part in dark blue), continues up to the top of the disk (3rd part in pink) and finally comes up from the bottom of the disk back to the center to close the loop (4th part in red).
As in the previous example, if we move a point where the path crosses the boundary we have to move the opposite point in the opposite direction so they remain antipodal to one another. We can start to rotate the 1st and 2nd parts of the path counter-clockwise in a continuous way until it looks like this:
The loop is not broken in any way. We continue to rotate it:
Until we've rotated the first half of the path 180 degrees:
And this is where the magic happens: if we imagine a particle following along the loop, it travels down part 2 (in dark blue) and when it reaches the center it turns around and travels up part three (in pink). That means that we can pull the point where the end of part 2 and the beginning of part 3 meet upwards without breaking the loop:
We can now pull the 2-3 part of the loop past the boundary:
At which points it's evident that the loop is contractible.
As Sharkos said, it's sliding points around on the boundary that messes with our intuition: when there is only one point where the path crosses the boundary we cannot shrink the loop to a point because any time we move that point it must be "reflected" in the opposite side of the circle (this is more of an appeal to our intuition rather than a rigorous proof). When the path crosses the boundary twice we can slide one pair of opposite points around to effectively "untangle" the loop.
Best Answer
The loops $ab^{-1}$ and $ab$ are not homotopic.
Imagine the holes are instead pegs, like the left figure here: Source:https://www.tinkercad.com/things/11tjAfAiQNw-two-pegs-two-holes
The loop $ab^{-1}$ is equivalent to an open loop $\mathsf{O}$ around both pegs. First, you wrap string around the pegs to make the shape of $ab^{-1}$; tie the start and end of the string into a knot at the base point. Then, notice you can simply nudge the string into an $\mathsf{O}$ shape without moving the base point knot or lifting up the string.
In contrast, the loop $ab$ is different. If you wrap the string around the pegs to make the shape of $ab$, you create a figure $\mathsf{8}$. There is no way to nudge the string into an $\mathsf{O}$ shape without moving the base point or lifting up the string over the pegs.
"Aren't they welded to the base point". Note that you are allowed to nudge any part of the string except the knot where the string starts and ends. The string is allowed to cross over itself and cross over the base point. If part of the string crosses over itself at the base point, you can still move that part; just don't move the base knot itself.
You can think about homotopies like this to help your intuition. When you make any loop out of string, try nudging the string without (a) moving the base point, or (b) lifting up the string over the pegs. The result is another homotopically equivalent loop, and all homotopically equivalent loops can be made in this way.
The pegs are obstacles. Wrapping a string around them creates a loop that you can't remove unless you lift that loop over the peg. In this way, just by recording which strings can be homotopically transformed into other strings, you can discover where the pegs are, even if the pegs are invisible. Thus this loop-wrapping approach (homotopy theory) uses strings within the space to reveal the invisible obstacles/holes outside the space.