Checking if a value is in the RGB range and then increment/decrement
Avoid repeating yourself
First, avoid having separate variables for r, g and b. It means you have to write all code three times. Just store the three components in a list, like so:
color = [0, 255, 0]

Then you can pass color to other functions, and have those functions iterate over the elements of the list.
Better way to create a triangle wave
What you are doing is basically creating a triangle wave shape for the intensity of each color component. Instead of keeping the current color value and a flag to store whether you are on the increasing slope or decreasing slope, just store a variable that holds the phase in a full cycle of the triangle wave.
In this case, I would store an integer between 0 and 511 for each color component. Initialize the phase like you did the color vector before:
phase = [0, 255, 0]

When updating the phase, do:
for i in range(3):
    phase[i] += colorVel
    phase[i] %= 512

Of course, this gives a sawtooth wave, and the values you get will be too high, but now you can map it onto a triangle wave with the correct amplitude:
color = list(map(lambda x: x if x &lt; 256 else 511 - x, phase))

Create a class to store the state of the iridescence
Even better would be to have a class manage all the internal state of an iridescence color, and allow it to be called as a function that generates the next color:
class Iridecence:
    def __init__(self, r, g, b, colVel=10):
        self.phase = [r, g, b]
        self.colVel = colVel

    def __call__(self):
        for i in range(3):
            if self.phase[i] &lt; self.colVel:
                self.phase[i] = random.randint(1, 100)
            self.phase[i] += self.colVel
            self.phase[i] %= 512;
        return list(map(lambda x: x if x &lt; 256 else 511 - x, self.phase))

Now you can use this as follow in your code:
irid = Iridescence(0, 255, 0)
color = irid()

while running:
    ...
    if keys[pygame.K_LEFT]:
        x -= vel
        color = irid()
    ...
    pygame.draw.rect(win, color, (x, y, width, height) )
    pygame.display.update()