No, it's a common practice. It's only considered bad style for expressions that are considerably longer than yours.
Python's Assignment Operator: Write Robust Assignments β Real Python
coding style - Assignment with "or" in python - Stack Overflow
With-Assignment statement - Ideas - Discussions on Python.org
Declaring return variables for assignment, no or yes?
What is an assignment operator in Python?
What is the := operator in Python?
What is def (:) in Python?
Videos
No, it's a common practice. It's only considered bad style for expressions that are considerably longer than yours.
The primary danger of doing something like this is the possibility that (in the second case) some_variable is False but not None (the integer 0, for instance) and you don't want to end up with y equal to None in that case.
I've been using python for quite some time without formal training. I absolutely love the language. I did C++ at uni decades ago.
So I was taught that you declare your variable initially, and then when you pass your variable to another function or class, then you need to return the result into your variable, else the updates don't reflect.
I'm way too far down the road to ask this now, but heck, why not! What do you guys do?
def x_plus_one(x: int)->int: return x+1
x = 10
x = x_plus_one(x)
print(x) # result = 11
x_plus_one(x)
print(x) # result = 11
from dataclasses import dataclass
def dx_plus_one(dx: Dx)->Dx: dx.x+1 return None
@dataclass class Dx: x: int
xx = Dx(x=10)
dx_plus_one(xx)
print(Dx.x) # result = 11
The dataclass example is a bit lame, I realise...
I know this is not possible for immutable classes like int, tuple, bool or str. But what about for mutable classes like dataframes, dataclasses, dict and list.
What do you prefer? What is the convention? Is explaining the theory worth explaining?