Web2py Python Language - Web2Py

What is Web2py Python Language?

Python can be defined as an aggregate of object-orientated and interactive language. it is an open source software. Guido van Rossum conceived python within the late 1980s.

Python is a language similar to PERL (practical Extraction and Reporting Language), which has received popularity because of its clear syntax and readability.

The main remarkable capabilities of Python are as follows −

  • Python is stated to be incredibly clean to examine and portable. It's statements may be effortlessly interpreted in some of operating systems, such as UNIX-based systems, Mac OS, MS-DOS, OS/2, and diverse variations of home windows.
  • Python is transportable with all the main operating structures. It uses a clean to recognize syntax, making the applications, which might be person pleasant.
  • It comes with a huge trendy library that supports many obligations.


From the above diagram, it is clearly visible that Python is a combination of scripting as well as programming language. They are interpreted within another program like scripting languages.

Versions of Python

Python has three production-quality implementations, which are called as CPython, Jython, and IronPython. These are also termed as versions of Python.

  • Classic Python a.k.a CPython is a compiler, interpreter and consists of built-in and optional extension modules which is implemented in standard C language.
  • Jython is a Python implementation for Java Virtual Machine (JVM).
  • IronPython is designed by Microsoft, which includes Common Language Runtime (CLR). It is commonly known as .NET

Starting Up

A fundamental Python application in any working system starts with a header. The programs are stored with a .py extension and Python command is used for running the programs.

As an instance, python_rstprogram.py will provide you with the required output. it will also generate mistakes if present.

Python makes use of indentation to delimit blocks of code. A block starts with a line ending with a colon and continues for all traces inside the comparable fashion which have a similar or higher indentation as the next line.

The output of the program will be −


Indentations of the programs are pretty crucial in Python. There are some prejudices and myths about Python's indentation regulations for the developers who're beginners to Python.

The thumb rule for all the programmers is –
Leading whitespace, which includes spaces and tabs at the beginning of a logical line of Python computes the indentation level of line.


  • The indentation level also determines the grouping of the statements.
  • It is common to use four spaces i.e. tab for each level of indentation.
  • It is a good policy not to mix tabs with spaces, which can result in confusion, which is invisible.

Python also generates a compile time error if there is lack of indentation.

Control flow Statements

The control flow of Python software is regulated by conditional statements, loops, and feature calls.

  • The If statement, executes a block of code underneath specified situation, along with else and elif(a combination of else-if).
  • The For declaration, iterates over an item, capturing every detail to a nearby variable for use by the attached block.
  • The while statement executes a block of code below the circumstance, that's real.
  • The With the statement encloses a code block in the context supervisor. It’s been brought as an extra readable opportunity to the strive/eventually announcement.



The statements in a typical Python program are organized and grouped in a particular format called, “Functions". A function is a group of statements that perform an action based on the request. Python provides many built-in functions and allows programmers to define their own functions.

In Python, functions are values that are handled like other objects in programming languages.

The def statement is the most common way to define a function. def is a single-clause compound statement with the following syntax –

The following example demonstrates a generator function. It can be used as an iterable object, which creates its objects in a similar way.


sh-4.3$ python main.py

Special Attributes, Methods, and Operators

The attributes, methods, and operators starting with double underscore of a class are usually private in behavior. Some of them are reserved keywords, which include a special meaning.
Three of them are listed below −

  • __len__
  • __getitem__
  • __setitem__

The other special operators include __getattr__ and __setattr__, which defines the get and set attributes for the class.

File I/O Functions

Python includes a functionality to open and close particular files. This can be achieved with the help of open(), write() and close() functions.

The commands which help in file input and output are as follows –


Command & Functionality



It helps in opening a file or document



It helps to write a string in file or document



It helps in reading the content in existing file



This method closes the file object.


Consider a file named “demo.txt”, which already exists with a text “This is a demo file”.

The string available after opening the file will be −

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Web2Py Topics