Professional Documents
Culture Documents
On
PYTHON
Degree in Computer Science and Engineering
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.
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.
7
Data Types in Python
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]
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
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
filter_none
edit
play_arrow
brightness_4
s = "Hello World"
for i in s :
print i
The output is :
10
r
filter_none
edit
play_arrow
brightness_4
L = [1, 4, 5, 7, 8, 9]
for i in L:
print i,
The output is :
145789
filter_none
edit
play_arrow
brightness_4
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
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
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.
filter_none
edit
play_arrow
brightness_4
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
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
17
s = "Look for Geeksforgeeks Python Section"
print(s)
# Global Scope
s = "Python is great!"
f()
print(s)
Output:
Python is great!
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
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.
# Creation of Arrays
import numpy as np
20
# Creating a rank 1 Array
[4, 5, 6]])
Output:
Array with Rank 1:
[1 2 3]
[[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
import numpy as np
# Initial Array
[2.6, 0, 7, 8],
print(arr)
22
sliced_arr = arr[:2, ::2]
# Printing elements at
# specific Indices
[3, 2, 1, 0]]
Output:
Initial Array:
[[-1. 2. 0. 4. ]
[ 4. -0.5 6. 0. ]
[ 2.6 0. 7. 8. ]
[ 3. -7. 4. 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