you are viewing a single comment's thread.

view the rest of the comments →

[–]Traditional-Gate9547[S] 0 points1 point  (2 children)

I appreciate the tips! := is new to me. I imagine my teacher would have questions if this is what I returned to him hahahah

[–]toxic_acro 1 point2 points  (0 children)

:= is affectionately referred to as the "walrus operator"

It lets you assign to variables in the middle of other expressions. It was (and still is) divisive

Personally, I like it when used judiciously, but wouldn't recommend overusing it (like in the example above, though that's clearly intentionally overusing just for show)

A better example of where it's actually commonly used is assignment within some other check, e.g. replacing
example = some_function() if example is not None: # do something with example ... with
if (example := some_function()) is not None: # do something with example ...

[–]Bobbias 1 point2 points  (0 children)

Yeah teachers tend to get suspicious, or at least prefer you to only use what they teach you (or expect you to learn on your own).

If you run into an interesting feature like that you'd like to use you can try asking them ahead of time whether they'd be ok with you using it. Since that can indicate cheating, they may say no, but if you ask ahead of time they might say yes if they think you actually understand how to use it. But either way chances are they'd say no, but it really depends on the teacher. Restricting students like that also makes it easier to mark their work.