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
  __init__() got multiple values for argument 'schema' dawid294 4 3,425 Jan-03-2024, 09:42 AM
Last Post: buran
  How to combine multiple column values into 1? cubangt 15 3,424 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Assigning a new value to variable uriel 1 1,687 Dec-04-2021, 02:59 PM
Last Post: Underscore
  Function - Return multiple values tester_V 10 4,834 Jun-02-2021, 05:34 AM
Last Post: tester_V
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,678 Mar-09-2021, 12:24 PM
Last Post: KMV
  code with no tuple gets : IndexError: tuple index out of range Aggam 4 3,023 Nov-04-2020, 11:26 AM
Last Post: Aggam
  assigning a variable :( gr3yali3n 0 1,393 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 1,956 Sep-15-2020, 01:42 PM
Last Post: rajesh3383
  Assigning Column nunique values to another DataFrame column Pythonito 1 1,958 Jun-26-2020, 06:52 AM
Last Post: hussainmujtaba
  How to pass multiple values from one sample to nc variable? Baloch 0 1,934 Jun-01-2020, 09:27 PM
Last Post: Baloch

Forum Jump:

User Panel Messages

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