Writing in Python
So far in my career as a developer, I’ve had pretty in-depth experience with ruby, ruby on rails, jQuery, javascript, react, and a few others. As I started to interview, I had a challenge/assessment sent to me from a company and they only wanted it done in one of the following: python, c/c++, or java. Now coming from a bootcamp that didn’t really go over any of those, I decided to take on the challenge and learn python.
Python is quite similar to ruby in that the syntax reads pretty much like standard english. After being so familiar with ruby, things started to blur in my mind. Let me show you an example.
In ruby, you create methods like so:
def method(num)
print num
endNow when you call the method, it’ll print out the number being passed in.
In python, it’s SO similar in syntax and different at the same time. See the following:
def method(num):
print numAnd that’s it! As I learned more about python, it has a lot of similar features that ruby provides — string manipulation, list (or arrays) iterations, dictionary (or hash) iterations, classes, testing, sort, and more! One thing to note is that there is no “end” keyword in python.
What matters is indentation!
If things aren’t properly indented, the syntax is wrong and things will break quite fast. Take your time when getting used to python. It’s relatively nice to pick up if you’re used to ruby.
Get Peter Kim’s stories in your inbox
Join Medium for free to get updates from this writer.
One cool thing I learned while learning and implementing python is using a for loop in brackets. For example take the following code :
to_do_list = [][ to_do_list.append('go buy groceries') for var in range(3)]#=> to_do_list = ['go buy groceries','go buy groceries','go buy groceries']
This block of code tells it to run 3 times. The appending to list is what is to be done, var is a variable, and in range(3) lets it know how many times to do it. It’s also possible to do things without a variable name. Say for instance you were using var somewhere else and you can’t come up with another variable name, you can also do:
to_do_list = [][ to_do_list.append('go buy groceries') for _ in range(3)]#=> to_do_list = ['go buy groceries','go buy groceries','go buy groceries']
The underscore is a placeholder for the variable and python has no problem with it. This is one of many things I’ve learned while learning Python. Check it out for yourself!
There are some things in python that I can’t explain properly so I may take more time to learn and digest said things before I even attempt to make it public. I’ll be back with more later. Hopefully.








