[Python] Do if statements work even if they are false in python? [closed]

Discussão em 'Python' iniciado por Stack, Abril 26, 2025.

  1. Stack

    Stack Membro Participativo

    I was making a game in which I came across this question. My code was:

    data = network1.get_data()
    if isinstance(data, Player):
    car2 = data
    car2.draw(screen)


    car2 is a Player object which comes through a sockets network, and when other car is not available, get_data() just returns a tuple. Player class has a method draw() which draws itself on a given screen. But when I run client code before anyone enters, it says AttributeError: 'tuple' object has no attribute 'draw'

    So I thought for a while if if statements affect a variable even if the condition is not true. What is the issue and why does it appear? How do you fix it?

    Continue reading...

Compartilhe esta Página