Unit 9 Introduction To Python: Structure
Unit 9 Introduction To Python: Structure
Introduction to
UNIT 9 INTRODUCTION TO PYTHON Python
Structure
9.0 Introduction
9.1 Objectives
9.2 History of Python
9.3 Need of Python
9.4 Packages for Cross platform application of Python
9.5 Getting started with Python
9.6 Program structure in python
9.7 Running the First program
9.8 Summary
9.0 INTRODUCTION
Python programming is widely used in Artificial Intelligence, Machine Learning,
Neural Networks and many other advanced fields of Computer Science. Ideally, It is
designed for rapid prototyping of complex applications. Python has interfaces with
various Operating system calls and libraries, which are extensible to C, C++ or Java.
Many large companies like NASA, Google, YouTube, Bit Torrent, etc. uses the
Python programming language for the execution of their valuable projects.
To build the carrier path the skill of programming can be a fun and profitable way,
but before starting the learning of this skill, one should be clear about the choice of
programming language. Before learning any programming language, one should
figure out which language suits best to the learner. As in our case the comparison of
C and Python programming languages may help the learners to analyze and generate
a lot of opinions about their choice of programming language. In this unit, I have
tried to compile a few of them to give you a clear picture.
Metrics Python C
It is a high-level, general-purpose
C is general-purpose procedural
Introduction & interpreted programming
programming language.
language.
Being compiled programming
Being Interpreted programming
language its execution speed is
language its execution speed is
Speed faster then that of the interpreted
slower then that of the compiled
programming language (i.e.
programming language (i.e. C).
Python).
Number of lines of code written Program syntax of C is quite
Usage in Python is quite less in complicated in comparison to
comparison to C Python.
199
Declaration of Variable type is
In C, declaration of variable type
not required, they are un-typed
is must, and it is done at the time
Declaration of and a given variable can be stuck
of its creation, and only values of
variables different types of values at
that declared type must be
different instances during the
assigned to the variables.
execution of any python program.
Error debugging is simple, as it
takes only one instruction at a Being compiler dependent
time. Compilation and execution language, error debugging is
Error
is performed simultaneously. difficult in C i.e. it takes the
Debugging
Errors are instantly shown, and entire source code, compiles it
execution stops at that instruction and finally all errors are shown.
only.
the same function can be used by Function renaming mechanism is
Function
two different names i.e. it not supported by C i.e. the same
renaming
supports the mechanism of function cannot be used by two
mechanism
function renaming different names.
Syntax of Python programs is The syntax of a C program is
Complexity Quite simple, easy to read, write comparatively harder than the
and learn syntax of Python.
It supports automatic garbage In C, the Programmer has to
Memory-
collection for memory explicitly do the memory
management
management. management.
Python is a General-Purpose
C is generally used for hardware
Applications programming language can be
related applications.
used for Microcontrollers also.
Built-in Library of built-in functions is Library of built-in functions is
functions quite large in Python. quite limited in C
Implementing Gives ease of implementing data Explicit implementation of
Data structures with built-in insert, functions is requited for the
Structures append functions. implementation of datastructures
Pointers functionality is not
Pointers Pointers are frequently used in C.
available in Python.
In this course you are given exposure to both programming languages i.e. C
and Python, based on your requirement you can choose your option to build
your carrer in programming.
9.1 OBJECTIVES
After going through this unit you will be able to:
……………………………………………………………………………………………
……………………………………………………………………………………………
……………………………………………………………………………………………
……………………………………………………………………………………………
……………………………………………………………………………………………
……………………………………………………………………………………………
……………………………………………………………………………………………
202 ……………………………………………………………………………………………
Introduction to
Python
After going through the section 9.2 of this unit, you understood the meaning
of Cross-platform applications and you are now aware of the potential of
204 Python as a cross-platform programming language, you also came to know
that the development of different type of applications require different types Introduction to
of packages, libraries, modules, frameworks etc. Now you might be confused Python
that what is the difference between these terms, are they same or different.
Let’s Clear your confusion first and then we will briefly discuss about the
functionality of different packages, used for the development of various
Python applications.
2) A package must hold the file __init__.py. This does not apply to
modules.
3) To import everything from a module, we use the wildcard *. But this
does not work with packages.
We will learn more about them, as we proceed in this course, don’t worry. To
start with we will discuss about various Frameworks and Libraries first, you
will be learning about their usage and also the usage of methods and
packages, later.
205
Keras : is a leading open-source Python library used for development of
neural networks and machine learning projects. It simplifies the process of
designing and development of neural networks for the beginners of machine
learning. Keras also deals with convolution neural networks(CNN) and
Recurrent Neural Networks (RNN), highly required in the field of Deep
Learning. It includes algorithms for normalization, optimizion, and activation
layers. Instead of being an end-to-end Python machine learning library, Keras
acts as a user-friendly, extensible interface that enhances modularity & total
expressiveness.
range of sources like CSV, SQL databases, JSON files, and Excel, can be
read. The data analysis & manipulation is a pre-requisite for most of the
machine learning projects, where a significant amount of time is spent to
analyse the trends and patterns hidden in the datasets. Using Pandas one can
manage complex data operations with just one or two commands, it comes
with several inbuilt methods for data handling, and it also serves as the
starting point to create more focused and powerful data tools.
may use tools, defined in modules, which may use files, defined in other
modules. Coming to our point, in python a file takes a module to get access
to the tools it defines, and also to the tools defined in other modules included
in programme. In python high level file has important path of control of your
program, where from you can start your application. Just refer to the figure
given below
To understand the structure of Python program, say there exist three files
a.py,b.py and c.py. The file model a.py is chosen for high level file . it is
known as a simple text file of statements. Files b.py and c.py are modules.
They are also text files of statements but they are generally not started
directly, but they are invoked by a.py i.e high level file.
This is the general discussion over the structure of Python program, although
Python includes all the components as they are in any other language such as
data types, conditional statements, looping constructs, functions, file
handling, Classes, Exception handling, Libraries, Modules, packages etc. We
will discuss a few of them over here and the rest will be discussed in the
subsequent units in this course
We will discuss in brief, some of the ways to work with Python, you may
choose any or try all and other options too.
210
Jupyter Notebook, Spyder, VS Code etc., even you can work with R- Introduction to
Programming. Python
Important: Before working with IDEs you need to understand how to work
with them and which ine is suitable, following are observations, currently:
3) Many a times the learners may not be equipped with the systems having
latest hardware configuarations, as desired for the installation of Python,
or their might be compatibility issues with operating syatem or may be
due to any reason you are not able to install and start your work with
Python. Under such circumstances the solution is Google Colab
Notebook (https://colab.research.google.com/notebooks/welcome.ipynb),
use this and just login with your gmail account and start your work on
Jupyter Notebook, as simple as that.
211
212
9.8 SUMMARY Introduction to
Python
213