Hi
I was wondering why I can’t use the walrus operator in my analysis3 environment.
I thought it was introduced in 3.8
Also feel free to provide reasons to not use it.
print(walrus_operator:=’cute’+’and useful?’)
Hi
I was wondering why I can’t use the walrus operator in my analysis3 environment.
I thought it was introduced in 3.8
Also feel free to provide reasons to not use it.
print(walrus_operator:=’cute’+’and useful?’)
The command you wrote has backticks as quotes, which is not supported in Python.
If those are meant to be double (or single) quotes, the command works correctly on the latest conda/analysis3 environment:
module purge
module use /g/data/xp65/public/modules
module load conda/analysis3
python3 -c 'print(walrus_operator:="cute"+"and useful?"); print(walrus_operator)'
correctly prints:
cute and useful?
cute and useful?
Meaning the walrus operator (:=) is correctly assigning the walrus_operator variable above.
Could you give more details about the error you are getting?
Oh thank you.
I should have tried a more simple case.
The issue was the how the interpreter saw colons.
The case below does not work, while the second one does.
for item in items:=[‘a’,‘b’,‘c’]:
print(item)
for item in (items:=[‘a’,‘b’,‘c’]):
print(item)
Yes, you will need to enclose in parenthesis in that case.
I will close this as it’s not related to conda/Analysis3 environemnts.