this post was submitted on 17 Oct 2024
44 points (95.8% liked)

Python

6287 readers
44 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

๐Ÿ“… Events

PastNovember 2023

October 2023

July 2023

August 2023

September 2023

๐Ÿ Python project:
๐Ÿ’“ Python Community:
โœจ Python Ecosystem:
๐ŸŒŒ Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS
 

I am working on a rudimentary Breakout clone, and I was doing the wall collision. I have a function that I initially treated as a Boolean, but I changed it to return a different value depending on which wall the ball hit. I used the walrus operator to capture this value while still treating the function like a bool. I probably could have just defined a variable as the function's return value, then used it in an if statement. But it felt good to use this new thing I'd only heard about, and didn't really understand what it did. I was honestly kind of surprised when it actually worked like I was expecting it to! Pretty cool.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] notnotmike 3 points 17 hours ago

Relatively new to Python so that's news to me.

Other languages I've used support assignment like that but I always avoid it, but they just used = so I'll give this walrus a try and see if the different syntax makes it any better in my mind