Python Forum
Help with finding correct topic in Python learning - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Help with finding correct topic in Python learning (/thread-18927.html)



Help with finding correct topic in Python learning - yahya01 - Jun-06-2019

Hi

I am starting at zero with Python. I need to know which topics in Python do I need to study to understand below two statements. The confusing part is more than one variable on the left side of assignment.

(x_train, y_train), (x_test, y_test) = mnist.load_data()
x_train, y_train = load_image_dataset(...)
Thanks

Regards


RE: Help with finding correct topic in Python learning - buran - Jun-06-2019

that's called unpacking (or iterable unpacking)

long story short - on the right side there is some data structure and values are assign to variables on the left side
in your first example mnist.load_data() shuld return tuple/list of 2 tuples/list with 2 elements each, e.g. ((1, 3), (5, 2)) (just arbitrary numbers for example) and then x_train = 1, y_train=3, x_test=5, y_test=2

check this SO question and accepted answer
https://stackoverflow.com/questions/6967632/unpacking-extended-unpacking-and-nested-extended-unpacking

there is also extended unpacking
https://www.python.org/dev/peps/pep-3132/