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

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

Homework Assignment #4, Finally! After years of adding unimportant sports,...

Finally! After years of adding unimportant sports, the IOC has finally added Shoe Tying to the Olympics. And you’ve been selected to write the software to handle the judging of t

List Assignment, Task This problem creates a list containing names. The li...

Task This problem creates a list containing names. The list of names will be printed, sorted, printed again in the new sorted order, written to a new output file, and searched. Ca

Conditionals- booleans, Booleans   Before we talk about  conditional...

Booleans   Before we talk about  conditionals, we require  to clarify the Boolean  data  type.  It has two values False and True. Typical statement that have Boolean values

Re.sub, how to use re.sub to seperate distint words and phrases when transl...

how to use re.sub to seperate distint words and phrases when translating text from English to Spanish or vis versa in python programming

Foundation of programming, hi i want to make a assignmnt of foundation of p...

hi i want to make a assignmnt of foundation of programming which include 4 task. I just want to know how much will be the price for that

Common Vulnerabilities, 1 Low Level Exploits 1.1 Savegames Jimmy is becomi...

1 Low Level Exploits 1.1 Savegames Jimmy is becoming increasingly frustrated at the computer game hes playing. He has a save right before the levels boss but he needs either more

Program that shows the use of all 6 math functions, Write an algorithm for ...

Write an algorithm for a program that shows the use of all 6 math functions. Write, test, and debug the program using Python. SAMPLE OUTPUT (not including author/program infor

Variables, Variables We cannot  go very far without variables. A variabl...

Variables We cannot  go very far without variables. A variable is a value related to a name that we can bind  to have a particular value  and  then  later use in an expression.

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