Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

python - Isolate multiple values from a function

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In Python we are allowed to do this ...

x_axis, y_axix, z_axis = sensor.acceleration

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...