30 DAYS OF PYTHON

Racheal Opene
3 min readJul 4, 2024

--

It is Day 2; I wrote my first python code 😉. The first python code I wrote was “hello world”.

print("hello world")

From the code above the print() function is used to print message to the screen.

Python Syntax

In writing Python code, you need to understand its basic syntax. A syntax is a set of rules that defines how a python program will be written. Let's look at the cornerstone in writing python syntax: Indentation

Indentation

Since python prioritizes readability, python uses indentation to define code blocks. This makes the code visually appealing and easy to read.

“Indentation” refers to the spaces at the beginning of a code line. The number of spaces is up to the programmer, the most common used is four or a tab. It is essential to be consistent throughout your code.

Look at the code below. Before the print function, you can see some spaces there.

Now when the space before the print function is taken away, it is going to return a syntax error. Let’s give it a try:

As you can see, it returned an indentation error. When coding in python, indentation is a requirement that plays a pivotal role in determining the flow of the code.

Comments

Comments can be used to explain Python code. They make the code more readable and can also be used to prevent execution when testing code. Comments start with #. For example, take a look at the code below:

Comments also be used to prevent the execution of a code. The later part of the code below was not executed.

Multiline Comments

To add multiline comment, you could insert # for each line or you could a triple quote in your code and place your code inside it. Let's see how it works.

Variables

For today, I will be introducing variables. By tomorrow, we will go deeper into variables. Variables are like containers for storing data values.

Check the code below, to see how I played around with variables:

Finally, tat will be all for today, tomorrow I will be looking more into variables and what we can actually do with them. So stay with me 😊.

--

--