Structured assignment, Python Programming

Assignment Help:

Structured assignment

Once  we have  tuples and lists, we may use  a nice trick  in assignment expression, based  on the packing and unpacking of tuples.

>>> a, b, c = 1, 2, 3

>>> a

1

>>> b

2

>>> c

3

Or, with lists,

 

>>> [a, b, c] = [1, 2, 3]

>>> a

1

>>> b

2

>>> c

3

When  you have  a list (or a tuple)  on the left-hand side of an assignment expression, you have  to have  a list of matching structure on the right-hand side.  Then  Python will "unpack" them  both,  and give  to the individual components of the structure on the left side.  You may get fancier with this function:

 

>>> thing = [8, 9, [1, 2], 'John', [33.3, 44.4]]

>>> [a, b, c, d, [e1, e2]] = thing

>>> c

[1, 2]

>>> e1

33.299999999999997

 


Related Discussions:- Structured assignment

Prime number, Use the function to compute and print the sum of first n prim...

Use the function to compute and print the sum of first n prime numbers.

Python Program Help, Write a Python program to accomplish the following. U...

Write a Python program to accomplish the following. Use modular design. Include at least 3 functions: one that returns zero values, one that returns one value, and one that retu

Python programme comparing for and while loops, 1)    Write a python progra...

1)    Write a python programmecomparing for and while loops like the following. Math Times table For Loop: 2x1=2 2x2=4 ..... 2x12=24 While Loop: 3x1=3 3x

Three layer neural network to classify the two sets of 3-D d, 1. Use a thre...

1. Use a three layer neural network to classify the two sets of 3-D data set. You should generate 100 samples for each data set based on the following criteria: Data set 1: generat

Conditionals-for and while, For and While   If we want  to do some o...

For and While   If we want  to do some operation or set of operations various  times, we can handle the process  in several  different types.  The most straightforward types

Expert, how can i become an expert & solution provider in the CS/IT field?

how can i become an expert & solution provider in the CS/IT field?

Programming embedded systems- interact with the environment, Interacting wi...

Interacting with the environment Computer systems have  to communicate with  the world around them,  getting information about  the external world, and  taking  actions  to cha

Normalize a vector, Normalize a vector Let's imagine we want  to norma...

Normalize a vector Let's imagine we want  to normalize a vector  of three  variables;  that  is to compute a new  vector  of three values,  such that its size  is 1. Here is o

Analytical models, Analytical models Analytical tools  are very importa...

Analytical models Analytical tools  are very important.  It may  be hard  to check  the  correctness of a machine by trying it in several possible  initial  conditions with  al

Indentation and line breaks, Every programming language has to have  some m...

Every programming language has to have  some method for indicating grouping of operations. Here is how you execute an if-then-else structure in Java:   if (s == 1){ s = s

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd