Built in functions in Python 3 | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 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?

13th Mar 2017, 9:17 PM
Some Name
3 Respuestas
+ 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()
13th Mar 2017, 9:52 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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.
13th Mar 2017, 10:25 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 1
Oh forgot that I can just use exponents to express roots and their indexes however, I still wonder about the 2nd question.
13th Mar 2017, 9:59 PM
Some Name