4

Is it possible do the following initializations in one line? As I am quite curious whether a shorter code is possible.

X = []
Y = []
2

2 Answers 2

8

You can initialize them using sequence unpacking (tuple unpacking in this case)

X, Y = [], []

because it's equivalent to

(X, Y) = ([], [])

You can also use a semicolon to join lines in your example:

X = []; Y = []
Sign up to request clarification or add additional context in comments.

Comments

2

You can use tuple unpacking (or multiple assignment):

X, Y = [], []

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.