Creating Classes in Python

Thomas Muscarello
2 min readJul 12, 2021

Since graduating from the Flatiron School, one of my main focuses aside from job searching was trying to learn new languages. That being said, my first new language attempt was Python.

At first I thought Python would be hard, however there are actually a lot of similarities between Python and Javascript. One being how to use/ create a class.

We use classes as a template for creating objects, and they enclose data with code to work on that data.

In Javascript to create a class, you would do the following:

However, creating a class in Python is fairly similar:

As you can see, both have a type of initialize method. For Python, it is literally def _init_() ,but for Javascript, it is the constructor() method. Both also require you to set self. the attributes of the class equal to a value.

You can also notice that rather having the curly boys {} to enclose the code, Python uses a colon :and indentation. Learning Python has actually been quite rewarding and fun. Having learned Javascript defiantly made the transition 100% easier.

--

--