Python VS Javascript

Python vs Javascript

Below is the comparison between Python and Javascript.

1. REPL (Read Eval Print Loop)

Python:

You’ll get it with the installation of python and call different python versions depending on the installation.

Javascript:

Javascript doesn’t have inbuilt REPL as most of the time developers run in a browser, but you can use REPL by installing node.js.

2. Mutability

Python:

Python has mutable and immutable data types like set (mutable) and list (immutable).

Javascript:

Javascript has no concept of mutable and immutable.

3. Strings

Python:

In python source code is ASCII by default unless you specify any encoding format.

Javascript:

Javascript should be encoded as UTF-16 and no built-in support for manipulating raw bytes.

4. Numbers

Python:

In python, you’ve different numeric types like integer (int), float, fixed-point decimal, etc.

Javascript:

Javascript has only floating point numbers only.

5. Hash tables

Python:

Python has built-in hash tables, called dictionaries, sets, etc, which can be used in hashing with keys and values.

Javascript:

Javascript has no built-in hash table support.

6. Inheritance

Python:

Python uses class-based inheritance model.

Inheritance in python

The example above shows you a class definition and __init__ function is a constructor.

Javascript:

Javascript uses prototype based inheritance model.

Inheritance in javascript

7. Code Blocks

Python:

Python uses indentation.

Javascript:

Javascript uses curly brackets.

8. Function Arguments

Python:

Python will raise an exception if a function is called with incorrect parameters and accepts some additional parameter passing syntax.

Javascript:

Javascript doesn’t care whether functions called with exact parameters are not as by default any missing parameter gets a value as “undefined” and any extra arguments end as special arguments.

9. Data types

Python:

Python has two similar data types list and tuple. Python list and javascript array are quite similar.

Javascript:

Javascript has inbuilt array type.

10. Properties and Attributes

Python:

Python allows to define an attribute using descriptor protocol where you can use a getter, setter functions.

Javascript:

Javascript objects have properties which can be composed of underlying attributes and it let’s you define a property.

11. Modules

Python:

Python calls itself as a batteries included language as it comes with a wide range of modules.

Javascript:

Javascript comes with very few modules like date, math, regexp, JSON and it has the functionality available through host environment like a web browser or other environment.

Leave a comment