1

I have a python function which splits out multiple values for X, Y, and Z coordinates. For example:

>>> sensor.acceleration
(2.4263221164, -1.0432706536, 9.5665047548)

What I need help with is assigning each of these values to a variable. To print these values I can do something like:

>>> print("X: %.2f, Y: %.2f, Z: %.2f" % (sensor.acceleration))
X: 2.43, Y: -1.01, Z: 9.58

But what I really need is how to set something like:

x_axis = 1st_value
y_axis = 2nd_value
z_axis = 3rd_value
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Alby
  • 426
  • 2
  • 7
  • 17
  • 1
    Does this answer your question? [Python, split tuple items to single stuff](https://stackoverflow.com/questions/18372952/python-split-tuple-items-to-single-stuff) – John Kugelman Dec 31 '20 at 02:07

1 Answers1

3

In Python we are allowed to do this ...

x_axis, y_axix, z_axis = sensor.acceleration
Red Cricket
  • 9,762
  • 21
  • 81
  • 166