Python Syntax: An Overview of Indentation, Variables, and Comments
In this article, you will learn the basics of Python syntax, which include indentation, variables, and comments.
Python has gained immense popularity due to its easy-to-read syntax, making it a great language for both beginners and experts. If you’re new to Python, understanding its syntax is the first step towards becoming proficient in the language.
Python Syntax Execution
Python syntax can be executed in the Command Line, as we saw on the previous topic, by typing the following directly into the command line:
>>> print("This is your first code in python, Congrats.")
This is your first code in python, Congrats.
It can also be done manually by writing a Python script on the server, and then executing it directly from the command line, using the .py extension:
C:UsersYour Name>myfirstpythonfile.py
Python Indentations
Unlike many other programming languages, Python uses indentation to delimit blocks of code. This means that you need to be careful about how you indent your code, as it can affect the way your program runs.
Indentation in Python is typically four spaces or one tab. It’s important to be consistent with your indentation throughout your program.
Normally, the first space in a code line is called an indentation. For Example:
Example: 
You will get an error if you do not indent the indentation in Python:
Example: 
It is up to you as a programmer how many spaces you want, but at least one needs to be included.
Example: 
Otherwise, Python will give you an error if you use inconsistent numbers of spaces in the same block of code:
Example: 
Semicolon’s In Python:
Python allows statements to be terminated by semicolons ( ; ) .
Sometimes it is helpful to place a number of statements on a single line if there is a need for it.
see an example below:
lower = []; upper = []
Python allows the semicolon (;) to be used optionally to put two statements on a single line, similar to C but many Python style guides prohibit the insertion of semicolons when putting multiple statements on a single line.
As you can see there is no difference in output:
lower = [] upper = []
Variables In Python
Variables are used in Python to store values that you can later use in your program.
To create a variable in Python, you simply choose a name for the variable and assign it a value using the = sign. For example:
Example: 
During the Python syntax chapter, you will learn more about Python variables and how they work.
Comments In Python
Comments are used in Python to explain what your code does.
They’re not executed as part of your program, but they can be helpful for other developers who are reading your code.
In Python, you can create a comment by starting a line with the # symbol. For example:
Example: 
This comment will not be executed as part of your program, but it can be helpful for explaining what your code does.
Conclusion
Python syntax is straightforward and easy to learn, even for beginners. By understanding the basics of indentation, variables, and comments, you’ll be able to start writing simple programs and exploring more advanced concepts. With practice and experience, you’ll become proficient in Python and be able to tackle more complex programming challenges.