>>> from math import sqrt
>>> def square_and_sqrt(x):
return x**2, sqrt(x)
>>> bigger, smaller = square_and_sqrt(9)
C++ needs to be able to do that because there's no good way to return multiple values
return std::make_tuple(pow(x, 2), sqrt(x));
auto t = square_and_sqrt(9);
std::cout << std::get<0>(t) << "\n"
metulburr@ubuntu ~ $ g++ -std=c++11 test.cpp -o test
metulburr@ubuntu ~ $ ./test
metulburr@ubuntu ~ $
I'm having a small problem with how I alter the attributes or even variables in called functions. To change them globally, I understand you can just declare them as global with the global keyword, but is there any other ways to do this? I don't want to make a lot of variables global.
Users browsing this forum: Bing [Bot] and 9 guests