Why does Python code look the way it does?

  • Last updated on July 7, 2023 at 7:37 PM
Python code looks like this:

It can be a bit confusing if it's your first time seeing Python code. You can view below the answers to the most commonly asked questions:
The color doesn’t have a technical application; it simply helps us differentiate the pieces of code.




Why are there spaces around some characters (like + and = )?

Spaces are there to improve readability. Spaces don’t affect the efficacy of your code; you could remove them, and the code would still work!



Why are some lines just plain blank?

Again, it's just to improve readability and prevent eye strain.




Why are some codes typed in a new line?

Each line in a code represents a programming statement. For example, let’s look at the instructions for drinking water:

  1. Take a glass 2. Fill it with water 3. Drink the water
Just like drinking water, a computer code also involves a sequence of steps. We command the computer to do each step using a programming statement. However, unlike us, the computer doesn’t know how much of the code is a step. For example, it may consider this entire line to be one step:
  1. Take a glass 2. Fill it with water 3. Drink the water
When we break code into a new line, the computer understands that the code in the previous line is the end of a step.
  1. Take a glass
  2. Fill it with water
  3. Drink the water



Does it matter whether I’m using capital letters or small ones?

Yes.

For example: Facebook, facebook, and FACEBOOK are just as different to the code editor as Facebook and Google are. Python is a “case-sensitive” language, which means you have to be specific with your capitalization.