Creating Classes in Python

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.

--

--

--

Software Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

101: API WORKING WITH POSTMAN

Tricks and Tips to Work with Lottie

Things you could do with Mix

Testing Article

Alot of code with white background

Connect your gadgets and gizmos to the world — or your kitchen

Experience debt

Flutter in Bitrise: Zero to Hero — Part 1

Building a Simple Grade Calculator using R

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Thomas Muscarello

Thomas Muscarello

Software Engineer

More from Medium

An Overview on Tenso

How to read and understand Python error messages

Python vs Java — Which is More Compatible for Web Development?

Python Generator