Here Is A Quick Learn For Python Syntax | Sample of Python Script

Learn Python Syntax

/ins>

Python Syntax Exercise

In this part of the Python tutorial, you will get to learn Python syntax. As we have mentioned before, in the getting started section of this Python tutorial we have learned that the entire Python Syntax can be written in the command line directly to execute any Python file. For example

You as a Python developer can also choose to execute a Python program by directly creating a Python file on your server. This python file is created with the help of a .py extension. This file with the .py extension can then be run in the command line in the below-mentioned way.

 

The Python Indentations

It is important for any learner of this programming language to remember that unlike many other programming languages where the indentations are only for the readability purposes, in Python the indentations actually plays a rather important role. This important role is that Python uses the indentations to indicate any particular block of codes. The below-mentioned example can be treated as a sample Python script.

And now, if you skip the indentations then Python will give you an error

 

The Comments

For the purpose of in-code documentation Python further has a type of commenting capability within itself. And if you wish to render any particular sentence as a comment then you just need to start that particular sentence with a #. This can be treated as a sample Python script. For example

 

The Docstrings

The entire Python programming language also comes with an extended documentation capability. And those extended documentation capabilities are known as docstrings. The docstrings can be of a single line or of multiple lines. To use this function of docstring in Python you just need to place triple quotes at the beginning and at the ending of the sentence that you want to serve as a docstring. For example


With this, we round up our tutorial for Python programming Syntax.