How do I only access one of the values:
my code:
def test():
a = 4
b = 5
c = 6
return a, b, c
a = test().a # only want "a" from the function
You could return a dictionary instead:
def test():
a = 4
b = 5
c = 6
return {"a":a, "b":b, "c":c}
print(test()["a"])
4
If you want to stick with your current approach, then the best you might be able to do would be to just print the first element from the tuple returned:
print(test()[0])
But this of course means that the caller would have to know that a
happens to coincide with the first value.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加