0% found this document useful (0 votes)
7 views

Module1-Elective 4

This module covers the fundamentals of Python programming, including its history, features, and various implementations. Students will learn about different IDEs, the basic concepts of Python, and the advantages of using Python as a programming language. The document also details the evolution of Python versions and the significance of its extensibility, portability, and ease of learning.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Module1-Elective 4

This module covers the fundamentals of Python programming, including its history, features, and various implementations. Students will learn about different IDEs, the basic concepts of Python, and the advantages of using Python as a programming language. The document also details the evolution of Python versions and the significance of its extensibility, portability, and ease of learning.

Uploaded by

Loki Legends
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Module No.

1
MODULE TITLE

PYTHON PROGRAMMING FUNDAMENTALS

MODULE OVERVIEW

This module provides a concept relevant to Python Programming Language. It provides the learners
an understanding of different compilers and interpreters' platforms. The instructor is also expected
to demonstrate the different features of the identified IDE and interpreter for the course.

LEARNING OBJECTIVES

At the end of the module, the students are expected to:


1. Explore the existing IDE that supports Python
2. Understand the basic concepts of Python and how it is implemented
3. Familiarize with the different features of the IDE supporting Python

LEARNING CONTENTS

PYTHON CONCEPTS and HISTORY

Python is a free general-purpose programming language with beautiful syntax. It is available across
many platforms including Windows, Linux, and Mac OS. Due to its
inherently easy to learn nature along with Object-Oriented features,
Python is used to develop and demonstrate applications quickly.
Python has the “batteries included” philosophy wherein the standard
programming language comes with a rich set of built-in libraries. It’s a
known fact that developers spend most of the time reading the code
than writing it and Python can speed up software development. Hosting
solutions for Python applications are also very cheap. Python Software
Foundation (PSF) nurtures the growth of the Python programming
language. A versatile language like Python can be used not only to
write simple scripts for handling file operations but also to develop
massively trafficked websites for corporate IT organizations.

Python was conceived in the late 1980s and its implementation was Guido van Rossum—Creator and
BDFL of Python Programming
started in December 1989 by Guido van Rossum at Centrum Wiskunde Language. (Image courtesy of
& Informatica (CWI) in the Netherlands as a successor to the ABC Wikipedia.org)
programming language, which was inspired by SETL[(SET Language)
is a very high-level programming language based on the mathematical theory of sets], capable of
exception handling and interfacing with the Amoeba operating system.

Van Rossum is Python’s principal author, and his continuing central role in deciding the direction of
Python is reflected in the title given to him by the Python community. He is the “Benevolent Dictator
For Life” (BDFL), which means he continues to oversee Python development and retains the final
say in disputes or arguments arising within the community.

Module 1 – Python Programming Fundamentals | 1


Often people assume that the name Python was
written after a snake. Even the logo of Python
programming language depicts the picture of two
snakes, blue and yellow. But, the story behind the
naming is somewhat different.
Python logo. (Image courtesy of Python.org)

Back in the 1970s, there was a popular BBC comedy TV show called “Monty Python’s Flying Circus”
and Van Rossum happened to be a big fan of that show. At the time when he began implementing
Python, Guido van Rossum was also reading the published scripts from “Monty Python’s Flying
Circus.” It occurred to him that he needed a name that was short, unique, and slightly mysterious,
so he decided to call the language “Python.”

Versions of Python:

• The first-ever version of Python (i.e., Python 1.0) was introduced in 1991. Since its inception
and introduction of Version 1, the evolution of Python has reached up to Version 3. x (till
2018).

• Python 2.0 was released on 16 October 2000 and had many major new features, including
a cycle-detecting garbage collector and support for Unicode. With this release, the
development process became more transparent and community-backed.

• Python 2.7's end-of-life date was initially set at 2015 then postponed to 2020 out of concern
that a large body of existing code could not easily be forward-ported to Python 3. No more
security patches or other improvements will be released for it. With Python 2's end-of-life,
only Python 3.6.x and later are supported.

• Python 3.0 (initially called Python 3000 or py3k) was released on 3 December 2008 after a
long testing period. It is a major revision of the language that is not completely backward-
compatible with previous versions. Many of its major features were backported to Python
2.6.x and 2.7.x version series. Releases of Python 3 include the 2to3 utility, which automates
(at least partially) the translation of Python 2 code to Python 3.

• Python 3.9.2 and 3.8.8 were expedited as all versions of Python (including 2.7) had security
issues, leading to possible remote code execution and web cache poisoning.

WHY LEARN PYTHON

There are a large number of high-level programming languages available, such as C, C++, and
Java. The good news is all high-level programming languages are very similar to one another. What
differs is mainly the syntax, the libraries available, and the way we access those libraries. A library
is simply a collection of resources and pre-written codes that we can use when we write our
programs. If you learn one language well, you can easily learn a new language in a fraction of the
time it took you to learn the first language.

Because there are many programming languages available today, the usual question to be an ask
by a newbie to the programming environment is “Why Do People Use Python?”. Given that there
are roughly more than a million Python users out there at the moment, there is no way to answer
this question with complete accuracy; the choice of development tools is sometimes based on
unique constraints or personal preference.

Module 1 – Python Programming Fundamentals | 2


But, up to this end, you may consider learning python by knowing its features, benefits, and usability
enumerated down below:

• High level
1. High-level languages are platform-independent which means that the programs written
in a high-level language can be executed on different types of machines.
2. A program written in the high-level language is called a source program or source code
and is any collection of human-readable computer instructions.
3. However, for a computer to understand and execute a source program written in a high-
level language, it must be translated into machine language. This translation is done
using either a compiler or interpreter.
4. A compiler is a system software program that transforms high-level source code written
by a software developer in a high-level programming language into a low-level machine
language.
5. The process of converting high-level programming language into machine language is
known as compilation.
6. Compilers translate source code all at once and the computer then executes the
machine language that the compiler produced.
7. Not all source code is compiled. With some programming languages like Python, the
source code is frequently executed directly using an interpreter rather than first compiling
it and then executing the resulting machine language.
8. An interpreter is a program that reads source code one statement at a time, translates
the statement into machine language, executes the machine language statement, then
continues with the next statement.
9. A programming paradigm is a style or “way” of programming. Major programming
paradigms are:
• An imperative is a paradigm of computer programming in which the program
describes a sequence of steps that change the state of the computer as each
one is executed in turn. Imperative programming explicitly tells the computer
“How” to accomplish a certain goal.
• Logical. The logical paradigm fits exceptionally well when applied to problem
domains that deal with the extraction of knowledge from basic facts and rules.
Rules are written as logical clauses with a head and a body; for instance, "Y is
true if X1, X2, and X3 are true." The idea in logical programming is that instead
of telling the computer how to calculate things, you tell it what things are.
Example: PROLOG.
• Functional. In functional programming languages, functions are treated as first-
class objects. In other words, you can pass a function as an argument to another
function, or a function may return another function.
• Object-Oriented. Object-oriented is the term used to describe a programming
approach based on objects and classes. The object-oriented paradigm allows us
to organize software as a collection of objects that consist of both data and
behavior.

• Scalable
1. The term "scalable" is most often applied to measuring hardware throughput and usually
refers to additional performance when new hardware is added to a system.
2. Python provides basic building blocks on which you can build an application, and as
those needs expand and grow.
3. Python's pluggable and modular architecture allows your project to flourish as well as
maintain manageability.

Module 1 – Python Programming Fundamentals | 3


• Extensible
1. As the amount of Python code increases in your project, you will still be able to organize
it logically by separating your code into multiple files, or modules, and be able to access
code from one module and attributes from another.
2. Python extensions can be written in C and C++ for the standard implementation of
Python in C (also known as CPython). The Java language implementation of Python is
called Jython, so extensions would be written using Java. Finally, there is IronPython,
the C# implementation for the .NET or Mono platforms. You can extend IronPython in
C# or Visual Basic.NET.

• Portable
1. Python can be found on a wide variety of systems, contributing to its continued rapid
growth in today's computing domain.
2. Python is available on practically every type of platform that has an ANSI C compiler.
Although there are some platform-specific modules, any general Python application
written on one system will run with little or no modification on another.
3. Portability applies across multiple architectures as well as operating systems.

• Easy-to-learn − Python has few keywords, a simple structure, and a clearly defined syntax.
This allows the student to pick up the language quickly.

• Easy-to-read − Python code is more clearly defined and visible to the eyes.

• Easy-to-maintain − Python's source code is fairly easy-to-maintain.

• A broad standard library − Python's bulk of the library is very portable and cross-platform
compatible on UNIX, Windows, and Macintosh.

• Interactive Mode − Python has support for an interactive mode that allows interactive
testing and debugging of snippets of code.

• Databases − Python provides interfaces to all major commercial databases.

• GUI Programming − Python supports GUI applications that can be created and ported to
many system calls, libraries, and windows systems, such as Windows MFC, Macintosh, and
the X Window system of Unix.

IMPLEMENTATION OF PYTHON ENVIRONMENT

Every Python implementation comes with several built-in and standard modules. These are
documented in The Python Standard Library. A few built-in modules are mentioned when they
interact in a significant way with the language definition. The implementation of Python is divided
into three categories:
Reference implementation
CPython is the reference implementation of Python. It is written in C, meeting the C89 standard with
several select C99 features (with later C versions out, it's considered outdated; CPython includes
its C extensions, but third-party extensions are not limited to older C versions, can e.g. be
implemented with C11 or C++). It compiles Python programs into an intermediate bytecode which
is then executed by its virtual machine. CPython is distributed with a large standard library written
in a mixture of C and native Python. It is available for many platforms, including Windows (starting
with Python 3.9, the Python installer deliberately fails to install on Windows 7 and 8; Windows
XP was supported until Python 3.5) and most modern Unix-like systems, including macOS
(and Apple M1 Macs, since Python 3.9.1, with experimental installer) and unofficial support

Module 1 – Python Programming Fundamentals | 4


e.g. VMS. Platform portability was one of its earliest priorities, during the Python 1 and 2 time-frame,
even OS/2 and Solaris were supported; support has since been dropped for a lot of platforms.
Other implementations

•PyPy is a fast, compliant interpreter of Python 2.7 and 3.6. Its just-in-time
compiler brings a significant speed improvement over CPython but several libraries
written in C cannot be used with it.
• Stackless Python is a significant fork of CPython that implements microthreads; it does
not use the call stack in the same way, thus allowing massively concurrent programs.
PyPy also has a stackless version.
• MicroPython and CircuitPython are Python 3 variants optimized for microcontrollers,
including Lego Mindstorms EV3.
• Pyston is a variant of the Python runtime that uses just-in-time compilation to speed up
the execution of Python programs.
• Cinder is a performance-oriented fork of CPython 3.8 that contains several optimizations
including bytecode inline caching, eager evaluation of coroutines, a method-at-a-
time JIT, and an experimental bytecode compiler.
Unsupported implementations
Other just-in-time Python compilers have been developed, but are now unsupported:

•Google began a project named Unladen Swallow in 2009, intending to speed up the
Python interpreter fivefold by using the LLVM, and improving its multithreading ability to
scale to thousands of cores, while ordinary implementations suffer from the global
interpreter lock.
• Psyco is a discontinued just-in-time specializing compiler that integrates with CPython
and transforms bytecode to machine code at runtime. The emitted code is specialized
for certain data types and is faster than the standard Python code. Psyco does not
support Python 2.7 or later.
• PyS60 was a Python 2 interpreter for Series 60 mobile phones released by Nokia in
2005. It implemented many of the modules from the standard library and some additional
modules for integrating with the Symbian operating system. The Nokia N900 also
supports Python with GTK widget libraries, enabling programs to be written and run on
the target device.
Cross-compilers to other languages
There are several compilers to high-level object languages, with either unrestricted Python, a
restricted subset of Python, or a language similar to Python as the source language:

• Cython compiles (a superset of) Python 2.7 to C (while the resulting code is also usable
with Python 3 and also e.g. C++).
• Nuitka compiles Python into C++.
• Pythran compiles a subset of Python 3 to C++.
• Pyrex (latest release in 2010) and Shed Skin (latest release in 2013) compile to C and
C++ respectively.
• Google's Grumpy (latest release in 2017) transpiles Python 2 to Go.
• IronPython (now abandoned by Microsoft) allows running Python 2.7 programs on the
.NET Common Language Runtime.
• Jython compiles Python 2.7 to Java bytecode, allowing the use of the Java libraries from
a Python program.
• MyHDL is a Python-based hardware description language (HDL), that converts MyHDL
code to Verilog or VHDL code.

Module 1 – Python Programming Fundamentals | 5


• Numba uses LLVM to compile a subset of Python to machine code.
• Brython, Transcrypt, and Pyjs (latest release in 2012) compile Python to JavaScript.
• RPython can be compiled to C and is used to build the PyPy interpreter of Python.

Note:
In summary, this is the list of Implementation for python:
Implementations of Python include:
• CPython – The reference implementation, written in C89. Some notable distributions include:
o PSF Python – Reference distribution that includes only selected standard libraries
o ActivePython – Distribution with more than 300 included packages
o Intel Distribution for Python – High-performance distribution with conda and pip package
managers.
• Stackless Python – CPython with coroutines
• MicroPython – Python 3 implementation for microcontroller platforms
• CLPython – Implementation, written in Common Lisp
• Cython – programming language to simplify writing C and C++ extension modules for the
CPython Python runtime.
• IronPython – Python for CLI platforms (including .NET and Mono)
• Jython – Python for Java platforms
• Pyjs – a framework (based on Google Web Toolkit (GWT) concept) for developing client-side
Python-based web applications, including a stand-alone Python-to-JavaScript compiler,
an Ajax framework, and widget toolkit
• PyPy – Python (originally) coded in Python, used with RPython, a restricted subset of Python that
is amenable to static analysis and thus a JIT.
• Numba – NumPy aware LLVM-based JIT compiler
• Shed Skin – a source-to-source compiler from Python to C++
• Nuitka – a source-to-source compiler that compiles Python code to C/C++ executables, or source
code.

Historic Python implementations include:


• Parrot – Virtual machine being developed mainly as the runtime for Raku, and intended to support
dynamic languages like Python, Ruby, Tcl, etc.
• Pyrex – Python-like Python module development project that has mostly been eclipsed by Cython
• Python for S60 – CPython port to the S60 platform
• Psyco – specialized JIT compiler project that has mostly been eclipsed by PyPy
• Unladen Swallow – performance-orientated implementation based on CPython which natively
executed its bytecode via an LLVM-based JIT compiler. Funded by Google, stopped circa 2011

INTEGRATED DEVELOPMENT ENVIRONMENT

A. The instructor may demonstrate the features of either of the two suggested IDEs:
- Visual Studio
- Pycharm
- List of Other IDE related to Python Programming Source: Wikipedia

B. Comparison of Features of Pycharm and Microsoft Visual Studio


i. Features of Pycharm

Module 1 – Python Programming Fundamentals | 6


Intelligent Coding Assistance
PyCharm provides smart code completion, code inspections, on-the-fly error
highlighting, and quick fixes, along with automated code refactorings and rich
navigation capabilities.
• Intelligent Code Editor
PyCharm’s smart code editor provides first-class support for Python, JavaScript,
CoffeeScript, TypeScript, CSS, popular template languages, and more. Take
advantage of language-aware code completion, error detection, and on-the-fly
code fixes!

• Smart Code Navigation


Use smart search to jump to any class, file or symbol, or even any IDE action or
tool window. It only takes one click to switch to the declaration, super method,
test, usages, implementation, and more.

• Fast and Safe Refactorings


Refactor your code the intelligent way, with safe Rename and Delete, Extract
Method, Introduce Variable, Inline Variable or Method, and other refactorings.
Language and framework-specific refactorings help you perform project-wide
changes.

Built-in Developer Tools


PyCharm’s huge collection of tools out of the box includes an integrated debugger
and test runner; Python profiler; a built-in terminal; integration with major VCS and
built-in database tools; remote development capabilities with remote interpreters; an
integrated ssh terminal; and integration with Docker and Vagrant.
• Debugging, Testing and Profiling
Use the powerful debugger with a graphical UI for Python and JavaScript. Create
and run your tests with coding assistance and a GUI-based test runner. Take full
control of your code with Python Profiler integration.

• VCS, Deployment and Remote Development


Save time with a unified UI for working with Git, SVN, Mercurial, or other version
control systems. Run and debug your application on remote machines. Easily
configure automatic deployment to a remote host or VM and manage your
infrastructure with Vagrant and Docker.

• Database tools
Access Oracle, SQL Server, PostgreSQL, MySQL, and other databases right
from the IDE. Rely on PyCharm’s help when editing SQL code, running queries,
browsing data, and altering schemas.

Web Development
In addition to Python, PyCharm provides first-class support for various Python web
development frameworks, specific template languages, JavaScript, CoffeeScript,
TypeScript, HTML/CSS, AngularJS, Node.js, and more.
• Python Web frameworks
PyCharm offers great framework-specific support for modern web development
frameworks such as Django, Flask, Google App Engine, Pyramid, and web2py,
including Django templates debugger, manage.py, and appcfg.py tools, special
autocompletion and navigation, just to name a few.

Module 1 – Python Programming Fundamentals | 7


• JavaScript & HTML
PyCharm provides first-class support for JavaScript, CoffeeScript, TypeScript,
HTML, and CSS, as well as their modern successors. The JavaScript debugger
is included in PyCharm and is integrated with the Django server run
configuration.

• Live Edit
Live Editing Preview lets you open a page in the editor and the browser and see
the changes being made in code instantly in the browser. PyCharm auto-saves
your changes, and the browser smartly updates the page on the fly, showing your
edits.

Scientific Tools
PyCharm integrates with IPython Notebook, has an interactive Python console, and
supports Anaconda as well as multiple scientific packages including Matplotlib and
NumPy.
• Interactive Python console
You can run a REPL Python console in PyCharm which offers many advantages
over the standard one: on-the-fly syntax check with inspections, braces, and
quotes matching, and of course code completion.

• Scientific Stack Support


PyCharm has built-in support for scientific libraries. It supports Pandas, Numpy,
Matplotlib, and other scientific libraries, offering you best-in-class code
intelligence, graphs, array viewers, and much more.

• Conda Integration
Keep your dependencies isolated by having separate Conda environments per
project, PyCharm makes it easy for you to create and select the right
environment.

Customizable and Cross-platform IDE


Use PyCharm on Windows, macOS, and Linux with a single license key. Enjoy a
fine-tuned workspace with customizable color schemes and key-bindings, with VIM
emulation available.
• Customizable UI
Are there any software developers who don't like to tweak their tools? We have
yet to meet one, so we've made PyCharm UI customization a breeze. Enjoy a
fine-tuned workspace with customizable color schemes and key bindings.

• Plugins
More than 10 years of IntelliJ platform development gives PyCharm 50+ IDE
plugins of different nature, including support for additional VCS, integrations with
different tools and frameworks, and editor enhancements such as Vim emulation.

• Cross-platform IDE
PyCharm works on Windows, macOS, or Linux. You can install and run PyCharm
on as many machines as you have, and use the same environment and
functionality across all your machines.

ii. Features of Microsoft Visual Studio

Module 1 – Python Programming Fundamentals | 8


VS Code supports development in multiple programming languages through a well-
documented extension model. The Python extension enables Python development
in Visual Studio Code, with the following features:
• Support for Python 3.4 and higher, as well as Python 2.7
• Code completion with IntelliSense
• Linting
• Debugging support
• Code snippets
• Unit testing support
• Automatic use of conda and virtual environments
• Code editing in Jupyter environments and Jupyter Notebooks

HOW TO INSTALL PYTHON APPLICATION AND INTERPRETER

This is the step-by-step procedure on how to


install Python on Windows:

Step 1) To download and install Python, visit the


official website of
Python https://www.python.org/downloads/ and
choose your version. We have chosen Python
3.6.3. Option two, go to Microsoft store type the
keyword python, then choose Python 3.9

Official Website of Python Python on Windows Store

Step 2) Once the download is completed, run


the .exe file to install Python. Now click on
Install Now.

Module 1 – Python Programming Fundamentals | 9


Step 3) You can see Python installing at this
point.

Step 4) When it finishes, you can


see a screen that says the Setup
was successful. Now click on
“Close”.

How to Install Pycharm


Here is a step by step process on how to download and install Pycharm IDE on Windows:

Step 1) To download PyCharm visit the


website https://www.jetbrains.com/pycharm/download/ and click the “DOWNLOAD” link under the
Community Section.

Module 1 – Python Programming Fundamentals | 10


Step 2) Once the download is complete, run
the exe for install PyCharm. The setup
wizard should have started. Click “Next”.

Step 3) On the next screen, change the


installation path if required. Click “Next”.

Step 4) On the next screen, you can


create a desktop shortcut if you want
and click on “Next”.

Module 1 – Python Programming Fundamentals | 11


Step 5) Choose the start menu folder.
Keep selected JetBrains and click on
“Install”.

Step 6) Wait for the installation to finish.

Step 7) Once the installation is


finished, you should receive a message
screen that PyCharm is installed. If you
want to go ahead and run it, click the
“Run PyCharm Community Edition” box
first and click “Finish”.

Module 1 – Python Programming Fundamentals | 12


Step 8) After you click on “Finish,” the following screen will appear.

Install Python Extension on VS Code

Step 1) install the Python extension for VS Code from the Visual Studio Marketplace. For additional
details on installing extensions, see Extension Marketplace. The Python extension is
named Python and it's published by Microsoft.

Step 2) Select your Python interpreter by clicking the status bar. A dialog box will appear. Choose
your appropriate interpreter.

Status Bar

Dialog box

Module 1 – Python Programming Fundamentals | 13


Apps for Python on Mobile Devices

You can download applications for creating and navigating programs on python. Go to Google
Play Store or Apps Store and Download app/s suitable to you. You can choose:

LEARNING POINTS

Python is a free general-purpose programming language with beautiful syntax. It is available across
many platforms including Windows, Linux, and Mac OS.

Python was conceived in the late 1980s and its implementation was started in December 1989 by
Guido van Rossum.

Why Python? Because of its best features such as high-level programming, scalable, easy to, read,
easy to learn, portable, and so on.

Implementation of Python environment can be divided into 3 categories, namely: A reference


implementation, Unsupported implementations, Cross-compilers to other languages

IDEs mentioned in this module are Pycharm and Visual Studio Code

Prepared by:
PATRICK V. MOLE, MIT
Faculty, College Information
and Technology Education

Module 1 – Python Programming Fundamentals | 14

You might also like