For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.
It makes sense to start learning by reading and watching videos about fundamentals and how things work.
Data Science and Machine Learning - 16 wks
Full-Stack Software Developer - 16w
Search from all Lessons
Curated list of small interactive and incremental exercises you can take to get better at any coding skill.
Curated section of projects to build while learning with simple instructions, videos, solutions, and more.
Guides on different topics related to the technologies that we teach in our courses
Social & live learning
The most efficient way to learn: Join a cohort with classmates just like you, live streams, impromptu coding sessions, live tutorials with real experts, and stay motivated.
Javier Leyva Seiglie
The most straight forward way to square a number in Python would be to use the built-in pow (power) method. It will receive two parameters, the number to square and the amount of times to power that number.
There are many ways or reasons to square a number in python: Using function power(), math.pow() and others, here is a more details explanation:
The first method we are presenting is exactly creating a function that will return the squared number of whatever number it receives: if it receives
x we will return
x * x.
As you should already know, a squared number is the number multiplied by itself.
Let say the square of
2 would be
2*2=4. If we were to choose
5, we would receive
25 and so on.
Keeping that in mind, we can create our function:
Python comes with a built in with a power (square) operator
**. The syntax is quite straight forward as all the other logic or math operators.
The only difference between the
pow resides in the first needs the math module imported and it always return a float number, even if the result of the operation has not a floating point or decimals (if you want to learn more about Float numbers, check What is a float in Python).
We can also use a built-in function in the numpy library. The syntax is as simple as:
You can find more of these articles at 4Geeks. Hope you enjoyed the reading and keep on the Geek side!