You are on page 1of 25

INDUSTRIAL TRAINING REPORT

On

PYTHON
Degree in Computer Science and Engineering

Submitted To: Submitted By:


Mrs. Preetpal Kaur Buttar prince
Assistant Professor GCS/1930059
CSE Department

Sant Longowal Institute of Engineering & Technology, Longowal,


District: Sangrur (PUNJAB, 148106)

1
2
ACKNOWLEDGEMENT

The satisfaction that accompanies the successful completion of any task would be
incomplete without the mention of people whose ceaseless cooperation made it
possible, whose constant guidance and encouragement crown all efforts with success.
I would like to express my gratitude and appreciation to Mr.Joseph Delgadillo for being
our guide and all those who gave me the possibility to complete this report.
I am also deeply thankful to my informants. Their names cannot be disclosed, but I want
to acknowledge their help and transparency during my training.

3
TABLE OF CONTENTS

 ABOUT COURSE'S PLATFORM
 ABOUT COURSE
 INTRODUCTION OF PYTHON
 DATA TYPES  IN PYTHON
 FILE HANDLING IN PYTHON
 PYTHON LIBRARIES
 NUMPY
 MATPLOTLIB
 PANDAS
 OPENCV
 CONCLUSION

4
ABOUT UDEMY

Udemy, Inc. is an American massive open online course (MOOC) provider aimed at
professional adults and students. It was founded in May 2010 by Eren Bali,
GaganBiyani, and OktayCaglar.

HISTORY
In 2007, Udemy founder Eren Bali built a software for a live virtual classroom while
living in Turkey. He saw potential in making the product free for everyone and moved to
Silicon Valley to founder a company two years later. The site was launched by Bali,
OktayCaglar and GaganBiyani in early 2010.

OVERVIEW
Udemy is a platform that allows instructors to build online courses on their preferred
topics. Using Udemy's course development tools, they can upload videos, PowerPoint
presentations, PDFs, audio, ZIP files and live classes to create courses.[citation
needed] Instructors can also engage and interact with users via online discussion
boards.Courses on Udemy can be paid or free, depending on the instructor.

AWARDS AND RECOGNITION


Udemy was ranked the number one large business in the annual “Best Places to Work
in the Bay Area” awards given by the San Francisco Business Times and the Silicon
Valley Business Journal, which recognizes Bay Area companies that have strong
company cultures, invest in their employees, and maintain high levels of employee
satisfaction. This is the fourth year Udemy was recognized as a “Best Place to Work in
the BaA.”

5
ABOUT COURSE
In this training program we have learnt about Python (Basics of programming, OOP’s
concept in Python, GUI toolkit), Database connectivity etc.
This training introduces object-oriented concepts and the Python programming
language. It is divided into different modules. The module begins with a brief
explanation of basic programming with Python and Object-Oriented concepts. This
training covered essential concepts on the building blocks of Python, object-oriented
programming, the use of SQLite database and development of GUIs for Python
applications.
In this module we learn about:

 INTRODUCTION TO PYTHON.
 BASICS OF PROGRAMMING IN PYTHON.
 PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING.
 SQLITE DATABASE CONNECTIVITY.
 PYTHON AND IT’S LYBRARIES

6
Introduction of Python
Python is a high-level, general-purpose and a very popular programming language.
Python programming language (latest Python 3) is being used in web development,
Machine Learning applications, along with all cutting edge technology in Software
Industry. Python Programming Language is very well suited for Beginners, also for
experienced programmers with other programming languages like C++ and Java.
This specially designed Python tutorial will help you learn Python Programming
Language in most efficient way, with the topics from basics to advanced (like Web-
scraping, Django, Deep-Learning, etc.) with examples.

Below are some facts about Python Programming Language:

1. Python is currently the most widely used multi-purpose, high-level programming


language.
2. Python allows programming in Object-Oriented and Procedural paradigms.
3. Python programs generally are smaller than other programming languages like
Java. Programmers have to type relatively less and indentation requirement of the
language, makes them readable all the time.
4. Python language is being used by almost all tech-giant companies like – Google,
Amazon, Facebook, Instagram, Dropbox, Uber… etc.
5. The biggest strength of Python is huge collection of standard library which can be
used for the following:
 Machine Learning
 GUI Applications (like Kivy, Tkinter, PyQt etc. )
 Web frameworks like Django (used by YouTube, Instagram, Dropbox)
 Image processing (like OpenCV, Pillow)
 Web scraping (like Scrapy, BeautifulSoup, Selenium)
 Test frameworks
 Multimedia
 Scientific computing
 Text processing and many more.

7
Data Types in Python

 Strings : A string is a sequence of characters. It can be declared in python by


using double quotes. Strings are immutable, i.e., they cannot be changed.
filter_none
edit
play_arrow
brightness_4

Assigning string to a variable


a = "This is a string"
print a

 Lists: Lists are one of the most powerful tools in python. They are just like the
arrays declared in other languages. But the most powerful thing is that list need
not be always homogenous. A single list can contain strings, integers, as well as
objects. Lists can also be used for implementing stacks and queues. Lists are
mutable, i.e., they can be altered once declared.
filter_none
edit
play_arrow
brightness_4

# Declaring a list
L = [1, "a" , "string" , 1+2]
print L
L.append(6)
print L
L.pop()
print L
print L[1]
The output is :

8
[1, 'a', 'string', 3]

[1, 'a', 'string', 3, 6]

[1, 'a', 'string', 3]

 Tuples: A tuple is a sequence of immutable Python objects. Tuples are just like
lists with the exception that tuples cannot be changed once declared. Tuples are
usually faster than lists.

filter_none
edit
play_arrow
brightness_4

tup = (1, "a", "string", 1+2)


print tup
print tup[1]
The output is :

(1, 'a', 'string', 3)

 Iterations: Iterations or looping can be performed in python by ‘for’ and ‘while’


loops. Apart from iterating upon a particular condition, we can also iterate on
strings, lists, and tuples.
Example1: Iteration by while loop for a condition

filter_none
edit
play_arrow

9
brightness_4

i=1
while (i < 10):
    i += 1
    print i,
The output is :

2 3 4 5 6 7 8 9 10

Example 2: Iteration by for loop on string

filter_none
edit
play_arrow
brightness_4

s = "Hello World"
for i in s :
    print i
The output is :

10
r

Example 3: Iteration by for loop on list

filter_none
edit
play_arrow
brightness_4

L = [1, 4, 5, 7, 8, 9]
for  i in L:
    print i,
The output is :

145789

Example 4 : Iteration by for loop for range

filter_none
edit
play_arrow
brightness_4

for  i in range(0, 10):


    print i,
The output is :

0123456789

11
Python programs are not compiled, rather they are interpreted. Now, let us move to
writing a python code and running it. Please make sure that python is installed on
the system you are working. If it is not installed, download it from here. We will be
using python
Python files are stored with the extension “.py”. Open text editor and save a file with
the name “hello.py”. Open it and write the following code:

filter_none
edit
play_arrow
brightness_4

print "Hello World"


# Notice that NO semi-colon is to be used

Linux System – Move to the directory from terminal where the created file (hello.py) is
stored by using the ‘cd’ command, and then type the following in the terminal :
python hello.py

Windows system – Open command prompt and move to the directory where the file is
stored by using the ‘cd’ command and then run the file by writing the file name as
command.

Variables
Variables need not be declared first in python. They can be used directly. Variables in
python are case sensitive as most of the other programming languages.
Example:
filter_none
edit
play_arrow
brightness_4

a=3

12
A=4
print a
print A
The output is :

Expressions
Arithmetic operations in python can be performed by using arithmetic operators and
some of the in-built functions.
filter_none
edit
play_arrow
brightness_4

a=2
b=3
c=a+b
print c
d=a*b
print d
The output is :

Conditions
Conditional output in python can be obtained by using if-else and elif (else if)
statements.
filter_none
edit
play_arrow
brightness_4

13
a=3
b=9
if b % a == 0 :
    print "b is divisible by a"
elif b + 1 == 10:
    print "Increment in b produces 10"
else:
    print "You are in else statement"
The output is :

b is divisible by a

Functions
A function in python is declared by the keyword ‘def’ before the name of the function.
The return type of the function need not be specified explicitly in python. The function
can be invoked by writing the function name followed by the parameter list in the
brackets.
filter_none
edit
play_arrow
brightness_4

# Function for checking the divisibility


# Notice the indentation after function declaration
# and if and else statements
def checkDivisibility(a, b):
    if a % b == 0 :
        print "a is divisible by b"
    else:
        print "a is not divisible by b"
#Driver program to test the above function
checkDivisibility(4, 2)
The output is :

14
a is divisible by b

So, python is a very simplified and less cumbersome language to code in. This easiness
of python is itself promoting its wide use.

Global and Local Variables in Python

Last Updated: 05-08-2020


Global variables are the one that are defined and declared outside a function and we
need to use them inside a function.

filter_none
edit
play_arrow
brightness_4

# This function uses global variable s


def f(): 
    print(s) 
  
# Global scope
s = "I love Geeksforgeeks"
f()
Output:

I love Geeksforgeeks

The variable s is defined as the string “I love Geeksforgeeks” before we call the function
f(). The only statement in f() is the “print s” statement. As there is no local s, the value
from the global s will be used.

filter_none

15
edit
play_arrow
brightness_4

# This function has a variable with


# name same as s.
def f(): 
    s = "Me too."
    print(s)
  
# Global scope
s = "I love Geeksforgeeks" 
f()
print(s)
Output:
Me too.

I love Geeksforgeeks.

If a variable with the same name is defined inside the scope of function as well then it
will print the value given inside the function only and not the global value.

The question is, what will happen if we change the value of s inside of the function f()?
Will it affect the global s as well? We test it in the following piece of code:

filter_none
edit
play_arrow
brightness_4

def f(): 

16
    print(s)
  
    # This program will NOT show error
    # if we comment below line. 
    s = "Me too."
  
    print(s)
  
# Global scope
s = "I love Geeksforgeeks" 
f()
print(s)
Output:
Line 2: undefined: Error: local variable 's' referenced before assignment

To make the above program work, we need to use “global” keyword. We only need to
use the global keyword in a function if we want to do assignments / change them. global
is not needed for printing and accessing. Why? Python “assumes” that we want a local
variable due to the assignment to s inside of f(), so the first print statement throws this
error message. Any variable which is changed or created inside of a function is local if it
hasn’t been declared as a global variable. To tell Python, that we want to use the global
variable, we have to use the keyword “global”, as can be seen in the following
example:
filter_none
edit
play_arrow
brightness_4

# This function modifies the global variable 's'


def f():
    global s
    print(s)

17
    s = "Look for Geeksforgeeks Python Section"
    print(s) 
  
# Global Scope
s = "Python is great!" 
f()
print(s)
Output:
Python is great!

Look for Geeksforgeeks Python Section.

Look for Geeksforgeeks Python Section.

A good Example

filter_none
edit
play_arrow
brightness_4

a=1
  
# Uses global because there is no local 'a'
def f():
    print('Inside f() : ', a)
  
# Variable 'a' is redefined as a local
def g():    
    a = 2
    print('Inside g() : ', a)
  
# Uses global keyword to modify global 'a'
def h():    

18
    global a
    a = 3
    print('Inside h() : ', a)
  
# Global scope
print('global : ',a)
f()
print('global : ',a)
g()
print('global : ',a)
h()
print('global : ',a)
Output:
global : 1

Inside f() : 1

global : 1

Inside g() : 2

global : 1

Inside h() : 3

global : 3

19
Python Numpy

Numpy is a general-purpose array-processing package. It provides a high-performance


multidimensional array object, and tools for working with these arrays. It is the
fundamental package for scientific computing with Python.
Besides its obvious scientific uses, Numpy can also be used as an efficient multi-
dimensional container of generic data.

Arrays in Numpy

Array in Numpy is a table of elements (usually numbers), all of the same type, indexed
by a tuple of positive integers. In Numpy, number of dimensions of the array is called
rank of the array.A tuple of integers giving the size of the array along each dimension is
known as shape of the array. An array class in Numpy is called as ndarray. Elements in
Numpy arrays are accessed by using square brackets and can be initialized by using
nested Python Lists.

Creating a Numpy Array


Arrays in Numpy can be created by multiple ways, with various number of Ranks,
defining the size of the Array. Arrays can also be created with the use of various data
types such as lists, tuples, etc. The type of the resultant array is deduced from the type
of the elements in the sequences.
Note: Type of array can be explicitly defined while creating the array.

# Python program for

# Creation of Arrays

import numpy as np

20
# Creating a rank 1 Array

arr = np.array([1, 2, 3])

print("Array with Rank 1: \n",arr)

# Creating a rank 2 Array

arr = np.array([[1, 2, 3],

                [4, 5, 6]])

print("Array with Rank 2: \n", arr)

# Creating an array from tuple

arr = np.array((1, 3, 2))

print("\nArray created using "

      "passed tuple:\n", arr)


Run on IDE

Output:
Array with Rank 1:

[1 2 3]

Array with Rank 2:

[[1 2 3]

[4 5 6]]

21
Array created using passed tuple:

[1 3 2]

 
Accessing the array Index
In a numpy array, indexing or accessing the array index can be done in multiple ways.
To print a range of an array, slicing is done. Slicing of an array is defining a range in a
new array which is used to print a range of elements from the original array. Since,
sliced array holds a range of elements of the original array, modifying content with the
help of sliced array modifies the original array content.
# Python program to demonstrate

# indexing in numpy array

import numpy as np

# Initial Array

arr = np.array([[-1, 2, 0, 4],

                [4, -0.5, 6, 0],

                [2.6, 0, 7, 8],

                [3, -7, 4, 2.0]])

print("Initial Array: ")

print(arr)

# Printing a range of Array

# with the use of slicing method

22
sliced_arr = arr[:2, ::2]

print ("Array with first 2 rows and"

    " alternate columns(0 and 2):\n", sliced_arr)

# Printing elements at

# specific Indices

Index_arr = arr[[1, 1, 0, 3],

                [3, 2, 1, 0]]

print ("\nElements at indices (1, 3), "

    "(1, 2), (0, 1), (3, 0):\n", Index_arr)


Run on IDE

Output:
Initial Array:

[[-1. 2. 0. 4. ]

[ 4. -0.5 6. 0. ]

[ 2.6 0. 7. 8. ]

[ 3. -7. 4. 2. ]]

Array with first 2 rows and alternate columns(0 and 2):

[[-1. 0.]

[ 4. 6.]]

23
Elements at indices (1, 3), (1, 2), (0, 1), (3, 0):

[ 0. 54. 2. 3.]

24
CONCLUSION

I believe the trial has shown conclusively that it is both possible and desirable to
use Python as the principal teaching language:
It is Free (as in both cost and sourcecode).
It is trivial to install on a Windows PC allowing students to take their interest
further. For many the hurdle of installing a Pascal or C compiler on a Windows
machine is either too expensive or too complicated
It is a flexible tool that allows both the teaching of traditional procedural
programming and modern OOP.
It can be used to teach a large number of transferable skills.
It is a real-world programming language that can be and is used in academia and
the commercial world.
It appears to be quicker to learn and, in combination with its many libraries, this
offers the possibility of more rapid student development allowing the course to be
made more challenging andvaried and most importantly, its clean syntax offers
increased understandingand enjoyment for students.

25

You might also like