8 Powerful Python Features You Should Know 2023

python features

Python Features

Let’s explore some highly significant python features:

1. In Python, a variety of basic data types are available like numbers, strings, lists and dictionaries.

2. It supports OOP with classes and multiple inheritance.

3. Python code can be grouped into modules and packages.

4. It support exception handling.

5. It has strongly and dynamically typed data types.

6. It contains advanced programming features like generators and list comprehensions.

7. It supports automatic memory management that free programmer from manually allocating and freeing memory in the code.

8. Python provides facility (py2exe) that turns python programs into packages and then can be run on other windows computers without needing to install python on that computer.

Untitled design1 1
Guido Van Rossum

Python History

  • Python is an interpreted, high level, general purpose, object oriented,versatile and very popular open source programming language.
  • It is designed by Guido Van Rossum in 1991.
  • Python is the product of Python Software Foundation that holds the copyright.
  • It is named after Monty Python(a British Comedy Group on Television).
  • Python can be used for any purpose like web development (server-side), system scripting ,scientific applications software development etc.
  • Python is ideally designed for rapid prototyping of complex applications and is widely used in advanced field of computing like artificial intelligence, natural language generation, neural networks etc.
  • Python can also be used to connect database systems,reading and modifying files etc.
  • It can work on different platforms like Windows, Mac, Linux, Raspberry Pi etc.
  • Python program can be treated as functional way or procedural way or an object oriented way.
  • Python program must be properly indented as scope in python relies on indentation using whitespaces (instead of curly brackets like in many other languages).
  • Both tabs and spaces are supported for indentation but the standard indentation required standard python code to use four spaces for indenting.
  • Python is an easy to use language that contains large standard library to support many common programming tasks like connecting web servers, searching text, reading and modifying files etc.
  • Standard library contain over 1,30,000 packages with a wide range of functionality including:
    1. Graphical User Interface
    2. Web Frameworks
    3. Multimedia
    4. Databases
    5. Networking
    6. Test Frameworks
    7. Automation
    8. Web Scraping
    9. Documentation
    10. System Administration
    11. Scientific Computing
    12. Text Process
    13. Image Processing etc.

  • Development environment called IDLE(Integrated DeveLopment Environment) has been bundled with the default implementation of the language.

Installing Python on Windows and Linux

  • Installing python is very simple, just you have to download most stable version of python from www.python.org
  • Now a days, python is already installed on most of the Windows computers (notably computers from HP).
  • Also in most of the Linux and UNIX distributions include recent python installed.

For Windows

  • Python releases for Windows are available on https://www.python.org/downloads/windows/
  • It is to be noted that python latest versions cannot be used Windows XP or earlier versions.
  • If your system has 32-bit processor then select either Windowsx86-32 executable installer and if your computer has 64-bit processor then select Windows x86-64 executable installer.
  • Select as per your system requirement and download it.
  • Next, double click the downloaded installer file to run.
  • A dialog box appears that look like
win installer
  • Make sure to check the box that asks “Add Python 3.x to PATH” to insure that the interpreter will be placed in your execution path.

For Linux

  • In Linux, python is already installed. But it may not be the latest version.
  • If it is python 2.x.x or not latest then you have to install the latest version.
  • Process of installing on Linux OS depends on the Linux distribution you are using.
  • The Linux tool pyenv can be used to manage multiple python versions on Linux. Command pyvenv helps you to switch between python versions.

Python Interpreter

  • Python uses interpreter i.e. code is executed as soon as it is written and hence support quick prototyping.
  • Interpreter is a language processor that converts high level code into machine language, line by line. If there is any error it reports at the same time.
  • It is very convenient for debugging program if first interpreted and then executed.
  • Interpreter works as:
Untitled Diagram.drawio2
  • Compiler works as:
Untitled Diagram.drawio3
  • Python is considered as interpreted language because programs are executed by an interpreter.
  • In python, interpreter can be used in two ways:
    1) Interactive mode and
    2) Script mode
  • In interactive mode, python prompt >>>indicates that it is ready to execute instruction. When we type instruction or expression and press return, immediately we get response.
  • Alternatively, in script mode, we can type set of instructions in a file(saved with extension .py) called script and then execute the file.
  • Working in interactive mode is very convenient for testing small set of instructions as we can type and execute immediately.
  • But for larger set of instruction, it is convenient to use script mode as it can be modified and executed as and when required.
  • By default, python source file are treated as encoded in UTF-8.
  • Note that, python interpreter acts as a simple calculator that cam perform arithmetic like +, -, *, / and ( ) for grouping.
  • In python input and output are distinguished by the presence or absence of prompt(>>>). Anything user type after prompt is treated as input and lines that do not begin with a prompt are output from the interpreter.

Comments in Python

  • Comments are remarks and non-executable.
  • Interpreter does not pay any attention towards the contents of comment.
  • Purpose of commenting is
    1) Instruction for programmer
    2) Explanation for program logic; what and why.
    3) Information about the identifiers.
    4) Helps in documentation.
    5) Increase readability of the program.
  • Comment in python starts with #(hash or pound or octothorpe) character and extends to the end of the line.
  • It may be a full line comment or it may follow some code or white spaces. For multiline each line begin with #
  • If comment is written in the quotes then it is not comment but a string.
  • Commenting is the art of explaining program logic. Comments are not the part logic and hence are not compulsory but they are helpful in understanding program logic.
  • While working professionally, programs are bigger and more complicated and became difficult to understand for others. Hence it is good ideas that at least 30% to 40% statements must be commented so that multiple programmers can work on same program.
  • While commenting, make sure that comment starts at the same indent level as the code under it.
  • Example:
    >>>r=1.234 #assign 1.234 to radius r
    >>>#area of circle
    >>>area=pi*r*r #area of circle

One thought on “8 Powerful Python Features You Should Know 2023

Leave a Reply

Your email address will not be published. Required fields are marked *