No, it's a common practice. It's only considered bad style for expressions that are considerably longer than yours.

🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί assignment-operators-in-python
Assignment Operators in Python - GeeksforGeeks
July 15, 2025 - These are the special symbols that carry out arithmetic, logical, and bitwise computations. The value the operator operates on is known as the Operand. Assignment Operators are used to assign values to variables.
🌐
W3Schools
w3schools.com β€Ί python β€Ί gloss_python_assignment_operators.asp
Python Assignment Operators
Python Operators Arithmetic Operators Assignment Operators Comparison Operators Logical Operators Identity Operators Membership Operators Bitwise Operators Operator Precedence Code Challenge Python Lists
Discussions

Python's Assignment Operator: Write Robust Assignments – Real Python
Alright so I saw this and was like "Seriously? An entire article about the assignment operator? This is so dumb, what more could there possibly be to learn about it?" And I must say I was surprised. A lot of it was functionality I didn't realize was afforded to me because of the assignment operator. I assumed it was because of the various objects and their own functionalities so it didn't occur to me that a good portion of it is actually due to the assignment operator as well. I knew a lot of this, but I did learn some new stuff as well. The biggest one in particular is the unpacking operator (*) when doing parallel assignment. Definitely worth reading the article and searching for that. More on reddit.com
🌐 r/Python
3
100
January 17, 2023
coding style - Assignment with "or" in python - Stack Overflow
Is it considered bad style to assign values to variables like this? x = "foobar" or None y = some_variable or None In the above example, x gets the value 'foobar'. More on stackoverflow.com
🌐 stackoverflow.com
With-Assignment statement - Ideas - Discussions on Python.org
I run into it somewhat frequently that I would like to write a code of the form with x = y: do_stuff() which should have the behaviour that inside the with x has the given value, and afterwards x is reset (usually deleted). For the most part it would a convenience tool to keep my namespace clean. More on discuss.python.org
🌐 discuss.python.org
0
July 11, 2024
Declaring return variables for assignment, no or yes?
I don't understand what you are asking. Your code seems like a classic example of using mutable vs immutable data types. Are you asking if I use return None explicitly? No, I don't. Are you asking if I prefer mutable or immutable? Well that depends on what I'm doing with it. One is not better than the other, they can't be compared like that. More on reddit.com
🌐 r/learnpython
14
2
December 3, 2023
People also ask

What is an assignment operator in Python?
An assignment operator in Python assigns values to variables. The most common is =, which sets the right-hand value to the left-hand variable, helping you store data for later use in your program.
🌐
wscubetech.com
wscubetech.com β€Ί resources β€Ί python β€Ί assignment-operators
Assignment Operators in Python: All Types With Examples
What is the := operator in Python?
The := operator in Python, called the walrus operator, lets you assign a value to a variable inside an expression. Introduced in Python 3.8, it helps write shorter code by combining assignment and conditions in one line.
🌐
wscubetech.com
wscubetech.com β€Ί resources β€Ί python β€Ί assignment-operators
Assignment Operators in Python: All Types With Examples
What is def (:) in Python?
You use def followed by : to define a function in Python. After the function name and parameters, you write the function body with indentation. The return statement is used to give back a value from the function.
🌐
wscubetech.com
wscubetech.com β€Ί resources β€Ί python β€Ί assignment-operators
Assignment Operators in Python: All Types With Examples
🌐
TutorialsPoint
tutorialspoint.com β€Ί different-forms-of-assignment-statements-in-python
Different Forms of Assignment Statements in Python
October 20, 2023 - Assignment statement in python is the statement used to assign the value to the specified variable. The value assigned to the variable can be of any data type supported by python programming language such as integer, string, float Boolean, list, tupl
🌐
Python
peps.python.org β€Ί pep-0572
PEP 572 – Assignment Expressions | peps.python.org
This is of the form NAME := expr where expr is any valid Python expression other than an unparenthesized tuple, and NAME is an identifier. The value of such a named expression is the same as the incorporated expression, with the additional side-effect that the target is assigned that value:
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί different-forms-of-assignment-statements-in-python
Different Forms of Assignment Statements in Python - GeeksforGeeks
May 10, 2020 - We use Python assignment statements to assign objects to names. The target of an assignment statement is written on the left side of the equal sign (=), and the object on the right can be an arbitrary expression that computes an object.
Find elsewhere
🌐
Real Python
realpython.com β€Ί python-assignment-operator
Python's Assignment Operator: Write Robust Assignments – Real Python
August 16, 2024 - In this tutorial, you'll learn how to use Python's assignment operators to write assignment statements that allow you to create, initialize, and update variables in your code.
🌐
WsCube Tech
wscubetech.com β€Ί resources β€Ί python β€Ί assignment-operators
Assignment Operators in Python: All Types With Examples
3 weeks ago - Learn about the Python assignment operator, including all types with examples. Understand how to use assignment operators effectively in your Python code.
🌐
Python Morsels
pythonmorsels.com β€Ί assignment-versus-mutation
Assignment vs. Mutation in Python - Python Morsels
May 18, 2024 - The list a still has five items in it, so a is unchanged: ... That didn't affect a at all. Our a variable still points to the original list: ... Python has two distinct types of change. Assignment changes a variable.
🌐
Python.org
discuss.python.org β€Ί ideas
With-Assignment statement - Ideas - Discussions on Python.org
July 11, 2024 - I run into it somewhat frequently that I would like to write a code of the form with x = y: do_stuff() which should have the behaviour that inside the with x has the given value, and afterwards x is reset (usually …
🌐
Berkeley
pythonnumericalmethods.studentorg.berkeley.edu β€Ί notebooks β€Ί chapter02.01-Variables-and-Assignment.html
Variables and Assignment β€” Python Numerical Methods
When programming, it is useful to be able to store information in variables. A variable is a string of characters and numbers associated with a piece of information. The assignment operator, denoted by the β€œ=” symbol, is the operator that is used to assign values to variables in Python.
🌐
DigitalOcean
digitalocean.com β€Ί community β€Ί tutorials β€Ί how-to-use-assignment-expressions-in-python
How To Use Assignment Expressions in Python | DigitalOcean
November 11, 2020 - For example, assignment expressions using the := syntax allow variables to be assigned inside of if statements, which can often produce shorter and more compact sections of Python code by eliminating variable assignments in lines preceding or following the if statement.
🌐
NetworkLessons
networklessons.com β€Ί home β€Ί python β€Ί python assignment operators
Python Assignment Operators
April 2, 2020 - Python assignment operators are one of the operator types and assign values to variables. We use arithmetic operators here in combination with a variable.
🌐
Stanford CS
cs.stanford.edu β€Ί people β€Ί nick β€Ί py β€Ί python-var.html
Python Variables and Assignment
A variable is created with an "assignment" = (one equal sign), with the variable's name on the left and the value it should store on the right: ... Variables and values are stored in the computer's memory, with each variable like a little box, labeled with the variable's name and containing ...
🌐
Real Python
realpython.com β€Ί ref β€Ί glossary β€Ί assignment
assignment | Python Glossary – Real Python
In Python, an assignment is a fundamental operation that allows you to attach values to variables.
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί declaring return variables for assignment, no or yes?
r/learnpython on Reddit: Declaring return variables for assignment, no or yes?
December 3, 2023 -

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?

🌐
Python documentation
docs.python.org β€Ί 3 β€Ί reference β€Ί simple_stmts.html
7. Simple statements β€” Python 3.14.3 documentation
In interactive mode, if the value ... not cause any output.) Assignment statements are used to (re)bind names to values and to modify attributes or items of mutable objects:...
🌐
Dyclassroom
dyclassroom.com β€Ί python β€Ί python-assignment-operators
Python - Assignment Operators - Python - dyclassroom | Have fun learning :-)
We use the assignment operator to assign any value or result of an expression to a variable. In the following Python code we are assigning integer value 10 to the variable x.
🌐
W3Schools
w3schools.com β€Ί python β€Ί python_variables_multiple.asp
Python Variables - Assign Multiple Values
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Note: Make sure the number of variables matches the number of values, or else you will get an error. And you can assign the same value to multiple variables in one line: