0

I tried this and that and was surprised that both methods work and give the same result. But there must be some sense in the difference in spelling, right?

rect = pg.rect.Rect(x, y, width, height)
rect = pg.Rect(x, y, width, height)

def draw():
        draw.rect(screen, color, rect)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174

1 Answers1

2

This is a case when you can easily dig into lib internals and investigate it on your own. In fact, there is a line from pygame.rect import Rect in pygame/__init__.py. There are no other reassignments, so there is no difference. It's just a shortcut for convenience.

Sergius
  • 908
  • 8
  • 20
  • 1
    Does this mean I don't have to use **`pg.rect.Rect()`** if I can use **`pg.Rect()`** ? It's just that in Mettiz's book I saw the syntax exactly **`pg.rect.Rect()`**, and in other examples (video on YouTube and in examples on the site) I saw **`pg.Rect()`** But you say that there is no fundamental difference and you can use any method of writing? – Александэр Спанчев Feb 18 '22 at 12:56
  • If you don't mind, I'll mark your answer as the answer a bit later. I will definitely do it. I just want to wait in case someone else comes in and gives a more detailed explanation. Thanks – Александэр Спанчев Feb 18 '22 at 13:47
  • 1
    Yes, you can use any method of writing. Btw, official docs refers to Rect directly: pygame.Rect: https://www.pygame.org/docs/ – Sergius Feb 19 '22 at 13:09