From the course: Python for JavaScript Developers

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Class definition in Python

Class definition in Python - Python Tutorial

From the course: Python for JavaScript Developers

Start my 1-month free trial

Class definition in Python

- [Instructor] Let's have a look at how we create objects in JavaScript compared to Python. So here we are in CH_04_02.JS. And we begin with a JavaScript object literal on line one, it's called literal soup. And on line two, we see that the attribute veggies, is an array of strings with names of vegetables. Then on line three, we have the cook method. And that method waits 1000 milliseconds with that set timeout, then it logs to the console, literally ready. Then on line 10, we have a soup constructor. And this is used to create instances of soup. So it uses this .veggies to give the new instance of veggies attribute of that array of vegetables. And it uses this .cook to assign that method that waits this time, 2000 milliseconds then it locks to the console constructed ready. Then if we scroll down a bit we see the usage of the modern JavaScript Class. And we have a soup class that has a constructor method and that…

Contents