Python Forum
Assigning multiple values using tuple
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assigning multiple values using tuple
#2
https://docs.python.org/3/tutorial/datas...-sequences Wrote:The statement
t = 12345, 54321, 'hello!'
is an example of tuple packing: the values 12345, 54321 and 'hello!' are packed together in a tuple. The reverse operation is also possible:

>>> x, y, z = t
This is called, appropriately enough, sequence unpacking and works for any sequence on the right-hand side. Sequence unpacking requires that there are as many variables on the left side of the equals sign as there are elements in the sequence. Note that multiple assignment is really just a combination of tuple packing and sequence unpacking.
Reply


Messages In This Thread
Assigning multiple values using tuple - by sivacg - Aug-06-2020, 07:07 PM
RE: Assigning multiple values using tuple - by Yoriz - Aug-06-2020, 07:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Assigning cycle values in a list nmancini 3 1,024 Sep-16-2024, 09:35 PM
Last Post: deanhystad
  __init__() got multiple values for argument 'schema' dawid294 4 9,884 Jan-03-2024, 09:42 AM
Last Post: buran
  How to combine multiple column values into 1? cubangt 15 7,078 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Assigning a new value to variable uriel 1 2,182 Dec-04-2021, 02:59 PM
Last Post: Underscore
  Function - Return multiple values tester_V 10 6,684 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 5,155 Mar-09-2021, 12:24 PM
Last Post: KMV
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 4,529 Nov-04-2020, 11:26 AM
Last Post: Aggam
  assigning a variable :( gr3yali3n 0 1,758 Sep-22-2020, 09:02 PM
Last Post: gr3yali3n
  Looking for help in Parse multiple XMLs and update key node values and generate Out.. rajesh3383 0 2,437 Sep-15-2020, 01:42 PM
Last Post: rajesh3383
  Assigning Column nunique values to another DataFrame column Pythonito 1 2,533 Jun-26-2020, 06:52 AM
Last Post: hussainmujtaba

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020