These two pieces of code output the same thing. What's the difference between them and when should we prefer using one over the other?
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_LEFT:
xc=-4
if event.key==pygame.K_RIGHT:
xc=+4
if event.key==pygame.K_UP:
yc=-4
if event.key==pygame.K_DOWN:
yc=+4
if event.type==pygame.KEYUP:
if event.key==pygame.K_LEFT or event.key==pygame.K_RIGHT:
xc=0
if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
yc=0
pressed=pygame.key.get_pressed()
if pressed[pygame.K_LEFT]:
xc=-4
elif pressed[pygame.K_RIGHT]:
xc=+4
else:
xc=0
if pressed[pygame.K_UP]:
yc=-4
elif pressed[pygame.K_DOWN]:
yc=+4
else:
yc=0