Shrijan Tripathi


Learning Python as Javascript Developer [Part 1]

Photo by Hitesh Choudhary on Unsplash

Learning Python as Javascript Developer [Part 1]

Shrijan Tripathi's photo
Shrijan Tripathi
·Mar 10, 2022·

3 min read

This probably will be a series of learning python as a Javascript developer. I can say that I know a few concepts of programming and I have been programming for more than 4 years in different programming languages mostly with JavaScript.

I will be pointing out things that seem unique to me here in this article except for semicolons. I know we don't need semicolons in python.

We will be using REPL to learn basic concepts for now.


➜ python3
Python 3.9.5 (default, May  4 2021, 03:36:27)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.sqrt(81)

Here, We are importing math as the module and the sqrt is the attribute inside it, which is basically function.


We may know that sqrt belongs to the math module but what about other methods in the math module. We can ask for help with Python REPL for it.

>>> help
Type help() for interactive help, or help(object) for help about the object.

Let's ask for help for the math module.

Help on module math:


    This module provides access to the mathematical functions
    defined by the C standard.

    acos(x, /)
        Return the arc cosine (measured in radians) of x.

        The result is between 0 and pi.

    acosh(x, /)
        Return the inverse hyperbolic cosine of x.

    asin(x, /)
        Return the arc sine (measured in radians) of x.

        The result is between -pi/2 and pi/2.

    asinh(x, /)
        Return the inverse hyperbolic sine of x.

    atan(x, /)
        Return the arc tangent (measured in radians) of x.

        The result is between -pi/2 and pi/2.

    atan2(y, x, /)
        Return the arc tangent (measured in radians) of y/x.

        Unlike atan(y/x), the signs of both x and y are considered.

    atanh(x, /)
        Return the inverse hyperbolic tangent of x.

    ceil(x, /)
        Return the ceiling of x as an Integral.

        This is the smallest integer >= x.

    comb(n, k, /)
        Number of ways to choose k items from n items without repetition and without order.

        Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates
        to zero when k > n.

        Also called the binomial coefficient because it is equivalent
        to the coefficient of k-th term in polynomial expansion of the

The list is huge, you can scroll down your terminal to find a full list of the functions, properties, and file available on the module.


    e = 2.718281828459045
    inf = inf
    nan = nan
    pi = 3.141592653589793
    tau = 6.283185307179586


Ok, a few properties seems to be available as properties like:

>>> math.pi
>>> math.inf
>>> math.e
>>> math.nan
>>> math.tau

You can even ask for help for the specific functions


Help on built-in function factorial in module math:

factorial(x, /)
    Find x!.

    Raise a ValueError if x is negative or non-integral.

Test it

>>> math.factorial(5)

Let's do more calculation

>>> n=5
>>> k=3
>>> math.factorial(n) / (math.factorial(k) * math.factorial(n-k))

Different ways of importing modules

  1. We can import the attribute directly from the module
>>> from math import factorial
>>> factorial(5)
  1. We can even rename the attribute imported
>>> from math import factorial as fac
>>> fac(5)


# / = "Floating division"
# // = "Inter division"

>>> fac(n) / (fac(k) * fac(n-k))
>>> fac(n) // (fac(k) * fac(n-k))

Thank you and to be contained.

Share this