Why You Should Learn Python

Adam Garcia

11/8/20243 min read

green snake on brown branch close-up photo
green snake on brown branch close-up photo

As a web developer mainly working with JavaScript, I find Python to be a very pleasant programming language. Its syntax is readable and clean, and concepts such as 'self' are a bit easier to grasp. Here’s a quick post on my thoughts on Python, especially for those coming from another language or struggling to learn a new programming language, and why you should consider learning Python. This post is inspired by my work on a Minesweeper CLI game I built. I'll be using it as an example to explain why Python is a great language to learn.

Syntax

Both objectively and subjectively, Python's syntax is easier to read. For example, it avoids curly braces for code blocks, doesn’t require variable declaration keywords like 'let' or 'const,' and uses keywords such as 'and,' 'or,' and 'not' in logical expressions, making Python closer to natural human language. This is just the tip of the iceberg when it comes to Python's readable syntax. While this might be subjective, if you've ever written pseudocode, you'll likely find that writing Python code feels similar. Try writing some functions, list or dictionary comprehensions, and loops, and let me know what you think of the syntax.

In my minesweeper CLI game, I started out writing how my code would work at a very high level:

To keep track of state and behavior, you need to define methods that take in one parameter, the "self" keyword, and prepend variables with "self". This allows us to refer to a specific object's variable or method.

For example, one instance of a game board can look different from another game board by passing in different column and row sizes. Python will keep track of the state (different game board size) and behavior (keeping track of the randomly placed mines).

Summary

In conclusion, these concepts are what I experienced while building this Python minesweeper CLI game. When i said that Python is both subjectively and objectively easier to read and write in, of course you're going to have people who dislike the language. On the other hand, it's difficult to argue the ease of readability of Python's syntax, and certain concepts compared to languages like JavaScript... I still like JavaScript though.

To see the full code, check out the Github Repo.

As you can see, the steps listed align pretty well with the code block on the right. Python’s syntax is easy to read and write, which made it a breeze for me to get started quickly and easily. Keep reading to find out how I set up the game logic.

  1. Define game board size

  2. Start game

  3. While game is not ended,

  4. Place x and y coordinates

  5. Show points

  6. If user hits a mine,

  7. End the game and show points

OOP Concepts

For those who work in the OOP paradigm, the keywords "this" (like Java and C++) and "self" (used in Swift, Ruby, and Python) usually refer to an instance of a class. These keywords allow us to access instance variables and methods while keeping track of state and behavior. Notice how I purposefully left out JavaScript in these examples. The "this" keyword can be a tricky concept to grasp when working with JavaScript, mainly because its behavior changes depending on the context. You need to be extra careful when using "this", as it can point to different things depending on how and where you call a function, not just where it's written.

Now, back to Python. The "self" keyword works just as you'd expect: it accesses instance variables and methods on an object of a class. It is directly tied to an instance of the class. If you're learning JavaScript and struggling with "this", you'll find that the concept in Python is a bit easier to grasp.