Python - Overview Of The Programming Language

Python Programming Language...Knowing it

Guido van Rossum invented the Python programming language. One of the founding goals of python as stated by Rossum is

“Create better, easier to use tools for program development and analysis.”

Python being one of the top 10 programming languages of today has evolved rapidly. Python has enabled computer users around the world with rapid software development process.Python allows multiple paradigms of programming which include procedural programming, 
object oriented programming and functional programming. Any Python program can have all these paradigms combined in it. 

Programming paradigms supported by Python

Python Software Foundation takes care of the development process and the evolution of Python programming language.

A Hello World Program in Python:

The Python interpreter executes Python programs. The Python interpreter can be invoked by typing python from the console window.

mac:/$ python

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 03:13:28)

[Clang 6.0 (clang-600.0.57)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>>print(‘Hello World’)

hello world

>>> 

The invoked Python interpreter acts as an interactive console as well. Python program blocks can be executed directly in the console window.

Python programs can be saved in a file with .py extension and can be executed with the Python interpreter.

The same print statement above, executed in the python interactive console can be executed from a file HelloWorld.py as well. Just open your favorite text editor and enter

print(‘Hello World’)

in a text file. Save the file as HelloWorld.py.

mac:/$python HelloWorld.py

Hello World

The python statements entered individually in the Python interactive console will be lost at the closing of the session. Hence, any reusable Python program can be stored as a .py file and executed several times as per the need.

Entry point of a Python Program

Python’s entry point function mechanism of a program is simple and different from languages like C, C++ and Java. The first function invoked in a Python file that is being executed becomes the entry-level function of the python program.

The __name__ variable is available inside any python module as the name of the module. However, __name__ will be set to __main__ in case if the module is under execution.

A Python module is the file containing Python code: It could include invocations, definitions or both.

The Python Interpreter and Python Byte Code

The Python interpreter interprets python statements in a Python program into python byte code and executes them. A Python program is different from a C Program or a C++ Program in terms of how it is executed.

A Python program is typically not directly translated into machine code. Instead a Python program is translated into byte code and executed. A Python program is slightly different from the execution of a Java program. When a Python program is executed, the byte codes are typically not stored in the file system like a Java .class file. The Python interpreter on the fly generates the byte code for a python program every time it is run.

However when a .py file is executed, if the Python program imports one or more modules, byte code is  generated for each of the imported module in the form of a .pyc file and stored in the file system. If the developer wants to generate .pyc file for the Python program as well, it can be done using the py_compile module.

 

import compileall

import sys

 

print('Hello World')

compileall.compile_file('/bytecode.py')

 

Running the above program with python interpreter produces the .pyc file inside the __pycache__ folder.

Remember, in general, neither the Python program text nor the byte code generated from Python programs can be directly executed on any machine. Python program execution is always through a Python interpreter.

 

Python Interpreter – Little Implementation Details

The standard Python interpreter is written in C language and the implementation is popularly known as CPython.  There are Python implementations developed using other programming languages as well:

 

Language in which Python interpreter is written

Name of the Python interpreter

Java

Jython

C#

Iron Python

RPython(translated into C)

pypy

 

Applications of the Python Programming Language

Python is a high level programming language. Python is widely used for

  • Web site development
  • Text Processing
  • Scientific Data processing
  • Data Analysis
  • UX development

and much more.

The current version of the Python programming Language is version 3.10.8.


Copyright 2023 © pythontic.com