Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python variable assignment order of operations

Is there a way to do a variable assignment inside a function call in python? Something like

curr= []
curr.append(num = num/2)
like image 340
Falmarri Avatar asked Dec 17 '22 23:12

Falmarri


2 Answers

Nopey. Assignment is a statement. It is not an expression as it is in C derived languages.

like image 112
msw Avatar answered Jan 03 '23 07:01

msw


I'm pretty certain I remember one of the reasons Python was created was to avoid these abominations, instead preferring readability over supposed cleverness :-)

What, pray tell, is wrong with the following?

curr= []
num = num/2
curr.append(num)
like image 45
paxdiablo Avatar answered Jan 03 '23 05:01

paxdiablo