Python - Statement Assignment Statements

Introduction

The following table illustrates the different assignment statement forms in Python, and their syntax patterns.

OperationInterpretation
test = 'Test'Basic form
test, ham = 'yum', 'YUM' Tuple assignment (positional)
[test, ham] = ['yum', 'YUM'] List assignment (positional)
a, b, c, d = 'test' Sequence assignment, generalized
a, *b = 'test' Extended sequence unpacking (Python 3.X)
test = ham = 'test' Multiple-target assignment
tests += 42 Augmented assignment (equivalent to tests = tests + 42)

The first form is the most common.

The other forms are all optional.

Related Topics