+ 1
Built in functions in Python 3
First question: I'm looking to do a calculator and wanted to do it without calling math.sqrt. So I look up what the function does and I only found this: def sqrt(x): """Return the square root of x. :type x: numbers.Real :rtype: float """ return 0.0 Can anyone explain what I'm seeing? Second question: Generally do people study each and every functions they use or they just accept that it does the job?
3 Respostas
+ 8
Try using x**.5
Does the same job as math.sqrt(x) and you don't have to import the whole math module. That is, if you only need it for the sqrt()
+ 8
I doubt everyone studies everything. If you use a given module often you learn its functions and study the documentation to understand how you can benefit from it. But then I think you just give in to the flow :)
If you ask me, this is actually the biggest advantage of Python, that you can build on others' codes to minimize the code-building part, so you can focus on the idea.
+ 1
Oh forgot that I can just use exponents to express roots and their indexes however, I still wonder about the 2nd question.