I want to return multiple return values for the input argument

【Overview】

1. Conclusion </ b>

2. How to write </ b>

3. What I learned from here </ b>

  1. Conclusion

Prepare multiple variables and prepare multiple with return </ b>!

  1. How to write

python


def calculation(num)
 no1 = (num + 100) * 100
 no2 = (num + 10) * 200
  return no1,no2
end

num = gets_to.i
a,b = calculation(num)

By doing the above, multiple variables were prepared (➡︎a, b), and multiple variables were prepared by return (➡︎no1, no2). Then, multiple return values (➡︎no1, no2) can be returned for the input argument (➡︎num). As a caveat, the variable will be "nil" if you do not prepare the number of variables to be substituted for the number of prepared variables (left side).

Referenced URL: Variable assignment when there are multiple return values

  1. What I learned from here

I knew that I could assign multiple variables, but I didn't think there were so many different ways to assign variables. I will post about multiple assignment from the URL below!

Referenced URL: Ruby multiple assignment summary

Recommended Posts