Python Basics | Comments in Python | Why is Python Popular | Websites Using Python

In this article we go through some of the fundamentals of Python programming language. Programming languages are the specially designed tool for expressing instructions to a computer system. Out of the various different programming languages, Python has emerged as one of the top frequently used languages especially since it is versatile, flexible and can handle a variety of tasks.

Why is Python so popular?

  • Easy to Learn: Python is comparatively easier when comparing with most other programming languages, since it is closer to human language and does not need the user to deal with certain specifications which are present in other languages.
  • Clear Syntax: Python code is usually well formatted, and quite comprehensible to the user which allows for quicker resolving of errors or maintenance.
  • Portability; Python is designed to be portable and hence they can be run on any platform. Python program also allows the development of a portable GUI application.
  • Extensible: The Python program can be extended through the use of modules which are similar to libraries in other languages, they contain a set of functions that can be implemented in the program.
  • Wide Usage: Python is a common language, and has about 8.2 million users worldwide. In recent times it has played an increasing role of usage in the fields of Machine Learning, Data Science and Artificial Intelligence.

Popular Websites That Uses Python

  • Instagram
  • Pinterest
  • Uber
  • Amazon
  • Spotify

Python syntax/statements/Indentation rules

In Python to print a statement, a single line of code is required without requiring any prior declarations or classes. Let us look at how a hello world statement in Python would look like.

print("Hello World")

Indentation is the space given at the beginning of a programming statement, Python also requires the program statements to be indented or it results in errors when the program is executed. It is used whenever a block of statements is to be executed.
Indentation Rules:

  • Python recommends 4 spaces to improve formatting of the indentation.
  • Tab and space should not be mixed in same block.
  • Colon( : ) is used to start a block followed by Enter, blocks can have their own inner blocks.

Let us look at an example of indentation:

if 100 > 45:  # Beginning of the block
    print("100 is greater than 5") # First block
    print("200 is greater than 100") # First Block
    if 200 > 100: # Beginning of inner block
        print("200 is greater than 100") # inner block

elif: # Beginning of the second block
    print("45 is less than 100") # second block
    print("This statement will not be printed") # second block

Comments in Python

Comments in Python are defined either through the # symbol which indicates the beginning of the single-line comment and turns the entire line into a comment. Statements within triple quotes (”’) also get treated as comments. To create multi-line comment statements either each line of the statement block should begin with a # or the block must be embedded in triple quotes (”’) .

Example of single-line comment in python:

# This program will print Hello World statement

print("Hello World")

Example of multi-line comments in python:

#The biggest planet
#in the Solar System is Jupiter


'''
The smallest planet 
in the solar system is Mercury
'''

Python follows dynamic typing, hence in python there is no single command for variable declaration. It stores the variable value to some memory location and then assigns the variable name to the memory container, the data type is not important as it will be retrieved during the program execution.

Next Chapter >> Download and Install Python | Best Text Editors/IDEs for Python|How Python Handles Code Execution

Leave a Comment