Académique Documents
Professionnel Documents
Culture Documents
“PYTHON”
Bachelor of Engineering
In
Computer Science
(Batch 2016-2020)
Submitted by
Durgesh Pawar (0115CS161031)
ABSTRACT
The objective of a practical training is to learn something about industries practically and to be
familiar with a working style of a technical worker to adjust simply according to industrial
environment. This report deals with the equipment’s their relation and their general operating
principle.
Python, an interpreted language which was developed by Guido van Rossum came into
implementation in 1989. The language supports both objects oriented and procedure-oriented
approach. Python is designed to be a highly extensible language. Python works on the principle
of “there is only one obvious way to do a task” rather than “there is more than one way to solve
a particular problem”. Python is very easy to learn and implement. The simpler syntax,
uncomplicated semantics and approach with which Python has been developed makes it very
easier to learn. A large number of python implementations and extensions have been developed
since its inception.
Training Cover provides both six weeks as well as six months industrial
Training in python. Python is divided into two parts as “Core python” and “Advance
Python”. Accordingly, all the basic and advanced topics are discussed in both of
the modules.
2|Page
COMPANY PROFILE
Indeyes Infotech Private Limited provide professional services to a Global Client. They have
expert teams of business analysts, application developers, web designers, quality assurance
specialists and online marketing experts have accomplished various projects from numerous
domains and varying complexity levels. Indeyes Infotech Private Limited has a large team of
designers, developers and project managers with adequate business and technical expertise to
design, implement and maintain solutions of any complexity. The company provide complete
development services in tune with the latest technologies and industry trends.
Indeyes Infotech Private Limited helps clients derive the measurable business value that they
have always been looking for from business and IT investments. we are a reputed training
(embedded system, .net, java, pcb designing, MATLAB, robotics, surface computing etc.),
development and placement company.
3|Page
TRAINER PROFILE
4|Page
ACKNOWLEDGEMENT
“Any serious and lasting achievement or success, one can never achieve without the help,
guidance and co-operation of so many people involved in the work.
This report documents the work done during the summer training done in Python under the
supervision of Mr. Ajeet Sir who gave me an opportunity to take professional training in
Indeyes Infotech Private Limited, Bhopal Madhya Pradesh.
I would like to express deep gratitude to Mr. Anurag Shrivastava, Head of Department
(Computer Science & Engineering), NRI Institute of Information Science & Technology,
without whose permission the training would not be possible.
I have tried my best to keep report simple yet technically correct. I hope I succeed in my
attempt.
5|Page
Contents
1.Introduction to Python 7
2.Operator 9
3.Collection in Python 14
4.Functions 22
5.Python modules 25
8.Technologies used 32
9.Outcomes 33
6|Page
Chapter 1: INTRODUCTION
PYTHON
Python is Interactive: You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
Python Features
Easy-to-learn: Python has few keywords, 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.
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 which allows
interactive testing and debugging of snippets of code.
7|Page
Portable: Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
Extendable: You can add low-level modules to the Python interpreter. These modules
enable programmers to add to or customize their tools to be more efficient.
8|Page
Chapter 2: OPERATORS
ARITHMETIC OPERATORS
% Modulus Divides left hand operand by right hand operand and returns b%a=0
remainder
9|Page
ASSIGNMENT OPERATOR
+= Add AND It adds right operand to the left operand and assign the c += a is
result to left operand equivalent to
c=c+a
-= Subtract AND It subtracts right operand from the left operand and assign the c -= a is
result to left operand equivalent to
c=c-a
*= Multiply AND It multiplies right operand with the left operand and assign c *= a is
the result to left operand equivalent to
c=c*a
/= Divide AND It divides left operand with the right operand and assign the result c /= a is
to left operand equivalent to
c = c / ac /= a
is equivalent
to c = c / a
10 | P a g e
IDENTITY OPERATOR
MEMBERSHIP OPERATORS
not in Evaluates to true if it does not finds a variable in the x not in y, here not in
specified sequence and false otherwise. results in a 1 if x is
not a member of
sequence y.
11 | P a g e
COMPARISON OPERATOR
& Binary AND Operator copies a bit to the result if it exists in (a & b) (means 0000 1100)
both operands
^ Binary XOR It copies the bit if it is set in one operand but not both. (a ^ b) = 49 (means 0011
0001)
~ Binary Ones It is unary and has the effect of 'flipping' bits. (~a ) = -61
Complement (means 1100 0011
in 2's complement form due
to a signed binary number.
<< Binary Left Shift The left operands value is moved left by the number of a << 2 =
bits specified by the right operand. 240 (means
1111 0000)
>> Binary Right The left operands value is moved right by the a >> 2 = 15
Shift number of bits specified by the right operand. (means 0000 1111)
12 | P a g e
LOGICAL OPERATOR
and Logical AND If both the operands are true then condition becomes (a and b) is true.
true.
not Logical NOT Used to reverse the logical state of its operand. Not(a and b) is false.
13 | P a g e
Chapter 3: COLLECTION IN PYTHON
LIST
The list is a most versatile data type available in Python which can be written as a list of comma-separated
values (items) between square brackets. Important thing about a list is that items in a list need not be of the
same type.
14 | P a g e
Built-in List Functions & Methods:
1
cmp(list1, list2)
3
max(list)
5
list(seq)
15 | P a g e
Python includes following list methods
1 list.append(obj)
2 list.count(obj)
3 list. extend(seq)
4 list.index(obj)
5 list.insert(index, obj)
6 list.pop(obj=list[-1])
7 list.remove(obj)
8 list.reverse()
9 list.sort([func])
16 | P a g e
TUPLES
A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The
differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples
use parentheses, whereas lists use square brackets.
tup1 = ();
To write a tuple containing a single value you have to include a comma, even though there is
only one value −
tup1 = (50,);
Like string indices, tuple indices start at 0, and they can be sliced, concatenated, and so on.
tup1[0]: physics
tup2[1:5]: [2, 3, 4, 5]
17 | P a g e
Updating Tuples:
Tuples are immutable which means you cannot update or change the values of tuple elements.
We are able to take portions of existing tuples to create new tuples as the following example
demonstrates −
To explicitly remove an entire tuple, just use the del statement. For example:
print tup
18 | P a g e
Basic Tuples Operations:
19 | P a g e
DICTIONARY
Each key is separated from its value by a colon (:), the items are separated by commas, and
the whole thing is enclosed in curly braces. An empty dictionary without any items is written
with just two curly braces, like this: {}.
Result –
dict['Name']: Zara
dict['Age']: 7
20 | P a g e
Updating Dictionary
We can update a dictionary by adding a new entry or a key-value pair, modifying an existing
entry, or deleting an existing entry as shown below in the simple example −
Result −
dict['Age']: 8
dict['School']: DPS School
To explicitly remove an entire dictionary, just use the del statement. Following is a simple
example –
21 | P a g e
Chapter 4: FUNCTIONS IN PYTHON
A function is a block of organized, reusable code that is used to perform a single, related
action. Functions provide better modularity for your application and a high degree of code
reusing. Python gives you many built-in functions like print(), etc. but you can also create
your own functions. These functions are called user-defined functions.
Defining aFunction
Simple rules to define a function in Python.
Function blocks begin with the keyword def followed by the function name and
parentheses ( ( ) ).
Any input parameters or arguments should be placed within these parentheses. You
can also define parameters inside these parentheses.
The first statement of a function can be an optional statement - the documentation string
The code block within every function starts with a colon (:) and is indented.
22 | P a g e
Calling aFunction
Defining a function only gives it a name, specifies the parameters that are to be included in
the function and structures the blocks of code.Once the basic structure of a function is
finalized, you can execute it by calling it from another function or directly from the Python
prompt. Following is the example to call printme() function −
Function Arguments
You can call a function by using the following types of formal arguments:
Required arguments
Keyword arguments
Default arguments
Variable-length arguments
23 | P a g e
Scope of Variables
All variables in a program may not be accessible at all locations in that program. This depends
on where you have declared a variable.
The scope of a variable determines the portion of the program where you can access a
particular identifier. There are two basic scopes of variables in Python −
Variables that are defined inside a function body have a local scope, and those defined outside
have a global scope.
This means that local variables can be accessed only inside the function in which they are
declared, whereas global variables can be accessed throughout the program body by all
functions. When you call a function, the variables declared inside it are brought into scope.
Following is a simple example −
return total;
sum( 10, 20 );
24 | P a g e
Chapter 5 PYTHON MODULES
A module allows you to logically organize your Python code. Grouping related code into a
module makes the code easier to understand and use. A module is a Python object with
arbitrarily named attributes that you can bind and reference.Simply, a module is a file
consisting of Python code. A module can define functions, classes and variables. A module
can also include runnable code.
Example:
The Python code for a module named aname normally resides in a file named aname.py.
Here's an example of a simple module, support.py
return
When the interpreter encounters an import statement, it imports the module if the module is
present in the search path. A search path is a list of directories that the interpreter searches
before importing a module. For example, to import the module support.py, you need to put the
following command at the top of the script −
25 | P a g e
A module is loaded only once, regardless of the number of times it is imported. This prevents
the module execution from happening over and over again if multiple imports occur.
Packages in Python
A package is a hierarchical file directory structure that defines a single Python application
environment that consists of modules and sub packages and sub-sub packages.
Consider a file Pots.py available in Phone directory. This file has following line of source
code −
def Pots():
Similar way, we have another two files having different functions with the same name as
above −
After you add these lines to init .py, you have all of these classes available when you import
the Phone package.
import Phone
Phone.Pots(
Phone.Isdn()
Phone.G3()
26 | P a g e
RESULT:
I'm 3G Phone
In the above example, we have taken example of a single functions in each file, but you can
keep multiple functions in your files. You can also define different Python classes in those
files and then you can create your packages out of those classes.
27 | P a g e
Chapter 6: PYTHON FILES I/O
The simplest way to produce output is using the print statement where you can pass zero or
more expressions separated by commas. This function converts the expressions you pass into
a string and writes the result to standard output as follows −
Result:
Python provides two built-in functions to read a line of text from standard input, which by
default comes from the keyboard. These functions are −
raw_input
input
The raw_input([prompt]) function reads one line from standard input and returns it as a string
(removing the trailing newline).
28 | P a g e
This prompts you to enter any string and it would display same string on the screen. When I
typed "Hello Python!", its output is like this −
The input([prompt]) function is equivalent to raw_input, except that it assumes the input is a
valid Python expression and returns the evaluated result to you.
This would produce the following result against the entered input −
Until now, you have been reading and writing to the standard input and output. Now, we
will see how to use actual data files.
Python provides basic functions and methods necessary to manipulate files by default. You
can do most of the file manipulation using a file object.
Before you can read or write a file, you have to open it using Python's built- in
open() function. This function creates a file object, which would be utilized to call other
support methods associated with it.
Syntax
file object = open(file_name [, access_mode][, buffering])
29 | P a g e
Here is a list of the different modes of opening a file −
Modes Description
r Opens a file for reading only. The file pointer is placed at the beginning of the file. This is the
default mode.
rb Opens a file for reading only in binary format. The file pointer is placed at the beginning of the
file. This is the default mode.
r+ Opens a file for both reading and writing. The file pointer placed at the beginning of the file.
rb+ Opens a file for both reading and writing in binary format. The file pointer placed at the
beginning of the file.
w Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist,
creates a new file for writing.
wb Opens a file for writing only in binary format. Overwrites the file if the file exists. If the file does
not exist, creates a new file for writing.
w+ Opens a file for both writing and reading. Overwrites the existing file if the file exists. If the file
does not exist, creates a new file for reading and writing.
wb+ Opens a file for both writing and reading in binary format. Overwrites the existing file if the file
exists. If the file does not exist, creates a new file for reading and writing.
a Opens a file for appending. The file pointer is at the end of the file if the file exists. That is, the
file is in the append mode. If the file does not exist, it creates a new file for writing.
ab Opens a file for appending in binary format. The file pointer is at the end of the file if the file exists.
That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
30 | P a g e
Chapter 7: PYTHON EXCEPTIONS HANDLING
Python provides two very important features to handle any unexpected error in your Python
programs and to add debugging capabilities in them −
Exception Handling: This would be covered in this tutorial. Here is a list standard
Exceptions available in Python: Standard Exceptions.
What is Exception?
An exception is an event, which occurs during the execution of a program that disrupts the
normal flow of the program's instructions. In general, when a Python script encounters a
situation that it cannot cope with, it raises an exception. An exception is a Python object that
represents an error.
When a Python script raises an exception, it must either handle the exception immediately
otherwise it terminates and quits.
Handling an exception
If you have some suspicious code that may raise an exception, you can defend your program
by placing the suspicious code in a try: block. After the try: block, include an except:
statement, followed by a block of code which handles the problem as elegantly as possible.
31 | P a g e
Chapter 8: TECHNOLOGIES USED BY PYTHON
DATA SCIENCE
This is the single, biggest reason why many programmers are learning Python in 2019. I know
many of my friends who are bored with their Java programming jobs in investment banks and are
learning Python on Udemy to make a career in data science due to the exciting work and high pay.
MACHINE LEARNING
This is another reason why programmers are learning Python in 2019. The growth of machine
learning in last a couple of years has been phenomenal and it’s rapidly changing everything around
us.
Algorithms become more sophisticated every day, the best example being Google’s search
algorithms, which can now answer what you are expecting. There are chatbots around to answer
your queries and Uber is totally driven by algorithms.
WEB DEVELOPMENT
Good old development is another reason for learning Python. It offers so many good libraries and
frameworks, e.g. Django and Flask, which make web development really easy.
A task which takes hours in PHP can be completed in minutes with Python. Python is also used a
lot for web scrapping. Some of popular websites on the Internet, like Reddit, are built using Python.
If you are interested in web development using Python I suggest you join the Python and Django
Full Stack Web Developer Bootcamp course by Josh Portilla.
HUGE COMMUNITY
You need a community to learn a new technology and friends are your biggest asset when it comes
to learning a programming language.
Thanks to Google, you can find the solution to any Python related problem in minutes.
Communities like Stack Overflow also bring many Python experts together to help newcomers.
One of the similarities between Python and Java is the sheer number of open source libraries,
frameworks, and modules available to do whatever you want to do. It makes application
development really easy.
In fact, Python has one of the best collections of machine learning and data science libraries,
including TensorFlow, Scikit-Learn, Keras, Pandas and many more.
32 | P a g e
OUTCOMES
The fundamental design cycle of computer science and computer programming: writing
code, executing it, interpreting the results, and revising the code based on the outcomes.
Usage of the fundamental atoms of programming: variables, mathematical operators,
logical operators, and Boolean arithmetic.
Control structures for developing dynamic programs: conditionals, loops, functions, and
error handling.
The core data structures for creating useful programs: strings, lists, dictionaries, and file
manipulation.
: object-oriented programming and computer algorithms.
33 | P a g e
QUESTIONS RELATED TO PYTHON
Python is an interpreted language. That means that, unlike languages like C and its
variants, Python does not need to be compiled before it is run. Other interpreted languages
include PHP and Ruby.
Python is dynamically typed; this means that you don’t need to state the types of variables
when you declare them or anything like that. You can do things like x=111 and then x="I'm
a string" without error
Python is well suited to object orientated programming in that it allows the definition of
classes along with composition and inheritance. Python does not have access specifiers
(like C++’s public, private).
In Python, functions are first-class objects. This means that they can be assigned to
variables, returned from other functions and passed into functions. Classes are also first-
class objects
Ans: An interpreted language is any programming language which is not in machine level code
before runtime. Therefore, Python is an interpreted language.
Ans: PEP stands for Python Enhancement Proposal. It is a set of rules that specify how to format
Python code for maximum readability.
Ans: A namespace is a naming system used to make sure that names are unique to avoid naming
conflicts.
Ans: It is an environment variable which is used when a module is imported. Whenever a module
is imported, PYTHONPATH is also looked up to check for the presence of the imported modules
in various directories. The interpreter uses it to determine which module to load.
34 | P a g e
Q7) Is python case sensitive?
Ans: Indentation is necessary for Python. It specifies a block of code. All code within loops,
classes, functions, etc. is specified within an indented block. It is usually done using four space
characters. If your code is not indented necessarily, it will not execute accurately and will throw
errors as well.
Ans: A function is a block of code which is executed only when it is called. To define a Python
function, the def keyword is used.
Ans: Iterators are objects which can be traversed though or iterated upon.
They are syntax constructions to ease the creation of a Dictionary or List based on existing iterable.
There are mutable and Immutable types of Pythons built in types Mutable built-in types
List
Sets
Dictionaries
Strings
Tuples
Numbers
In Python, every name introduced has a place where it lives and can be hooked for. This is known
as namespace. It is like a box where a variable name is mapped to the object placed. Whenever the
variable is searched out, this box will be searched, to get corresponding object.
35 | P a g e
It is a single expression anonymous function often used as inline function.
A lambda form in python does not have statements as it is used to make new function object and
then return them at runtime.
Pass means, no-operation Python statement, or in other words it is a place holder in compound
statement, where there should be a blank left and nothing has to be written there.
In Python, iterators are used to iterate a group of elements, containers like list.
A unit testing framework in Python is known as unittest. It supports sharing of setups, automation
testing, shutdown code for tests, aggregation of tests into collections etc.
A mechanism to select a range of items from sequence types like list, tuple, strings etc. is known
as slicing.
The way of implementing iterators are known as generators. It is a normal function except that it
yields expression in the function.
36 | P a g e