Python Formatting

Samantha Aleman
2 min readMar 30, 2021

Lets talk a little about Python today!

I’m in the process of learning Python so that can be my preferred backend language as opposed to Ruby. Mainly because of the fact that I have seen that Python is used heavily more in the tech community as opposed to Ruby.

Today I will talk a little about the formatting when you write out a new function.

I prefer working in Javascript so I am very used to writing out functions like this:

And even in Ruby you’d write out a function like this:

However with Python formatting is very important. In a new file you must drop down two lines before you start coding, and the way you write out a function is a little different :

You don’t need curly brackets like in JS, you just need a colon. You also don’t need an end at the end like you do in Ruby.

Another thing about formatting in Python is that you must space the following lines accordingly or your code won’t run. For example in the above example I must indent in the second line and if there were a third line, like for a while loop or an if statement, I would also need to indent.

So far from what I have learned, *disclaimer not alot just the basics* theres alot of similarities between Javascript and Ruby to Python, and I am excited to keep learning!

--

--

Samantha Aleman

Fullstack software engineer with a passion for code, space, and corgis