0
Is there any way to access a value passed on the condition of a if
? For example:
a = int(input('Digite um numero: '))
b = int(input('Digite outro numero: '))
if((a-b) > 0):
print(f'O numero {(a-b)} é maior que Zero')
Instead of having to repeat the (a-b)
within the print
, it is possible to just call some magic method that pulls information from the created condition on the top row?
Earned my +1 by remembering that this will exist... But every time I see this PEP I think the language will become Phpython
– fernandosavio
@fernandosavio this will depend only on the developers, in moderate use. This example is very forced and has no advantages over create a variable. I particularly prefer the variable here because it becomes more readable, but there are cases that the assignment Expression will help a lot.
– Woss
I reread the PEP now and, in my opinion, will help at most in 5% of cases. Only that the code will be less readable... I even found it strange to approve a PEP that seems to break the Zen of Python...
– fernandosavio
I guess my biggest fear isn’t the Feature, and yes what people will do to her... hahahaha
– fernandosavio
@fernandosavio The idea is to supply the 5%... things like
while chunk := file.read(8192)
i think they will be much more readable and avoid having to start the variable with a "random" value, make a precondition of thewhile
that initially will not make sense and only within the loop assign the real value to the variable.– Woss
It’s true, just confirms my last comment... I’m scared of the "creativity" that people will use to create absurd codes. uaheuaheuah
– fernandosavio