Learning Python (and other programming languages)

I’ve spent the last 20 years developing websites using the Microsoft stack. My first adventures in website development were with classic ASP 3.0 and Visual Interdev. I wrote COM objects using Visual Basic 6.0 and went through countless data access technologies. I remember forgetting to call Recordset.MoveNext while looping through a RecordSet object and having the server hang in an infinite loop. Moving to .NET 1.0 felt like a huge step forward as did all the versions of .NET that followed.

My new job is at the complete opposite end of the development spectrum. There is very limited Microsoft technologies found in the building besides a few desktops that run Windows 10. Everything that I will be building here will be based on some form of the LAMP stack (Linux, Apache, MySQL and Python).

I spent some time WAY back in University playing around with Python and tkinter to write some small Linux applications. I also used Python more recently to create some small utilities that we used at my previous employer. My next project, however, will be 100% written in Python and Django.

To help knock the rust off my Python skills and to move them past the level of “struggling beginner”, I found the site Exercism. This site offers free exercises in many different programming languages. There are three different sizes of exercises that take anywhere from 10 minutes to an hour to complete. The exercise files come with unit tests that allow you to test your code before submitting it for review.

A sample exercise would be:

Given a year, report if it is a leap year.
The tricky thing here is that a leap year in the Gregorian calendar occurs:
on every year that is evenly divisible by 4
 except every year that is evenly divisible by 100
   unless the year is also evenly divisible by 400
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap year, but 2000 is.

You would be responsible for creating the function is_leap_year that would fulfill the requirements of the exercise.

My code solution was:

def is_leap_year(x):

   return x % 4 == 0 and (x % 100 != 0 or x % 400 == 0)

def is_leap_year(x):
    return x % 4 == 0 and (x % 100 != 0 or x % 400 == 0)

The best part of Exercism is that once you submit your code, you are able to look at code that other people have submitted for the same exercise. This has greatly helped me to better understand the nuances of the Python programming language.

There are currently over 100 different exercises on Exercism for Python. They offer a great opportunity to practice and learn Python. And best of all, it is free!