Shalvi Python Internship Report - Word
Shalvi Python Internship Report - Word
ON
SUBMITTED TO
DR APJ ABDUL KALAM TECHNICAL UNIVERSITY, LUCKNOW
IN PARTIAL FULLFILMENT OF THE REQUIREMENT FOR THE
DEGREE OF
BACHELOR OF TECHNOLOGY
IN
“COMPUTER SCIENCE & ENGINEERING”
TABLE OF CONTENT:-
INTRODUCTION TO PYTHON
CHARACTERISTICS OF PYTHON
FEATURES OF PYTHON
VARIABLE TYPES
ASSIGNING VALUES TO VARIABLES
RESERVED WORDS
DATA STRUCTURES IN PYTHON
(LISTS, DICTIONARY, TUPLES, SETS)
PYTHON – BASIC OPERATORS
PYTHON – DECISION MAKING
PYTHON – LOOPS
PYTHON – NUMBERS
NUMBER TYPES CONVERSION
PYTHON – STRING
PYTHON – IDENTIFIERS
RULES OF IDENTIFIERS IN PYTHON
PYTHON – FUNCTION
DEFINING A FUNCTION
THE RETURN STATEMENT
SCOPE OF VARIABLES
GLOBAL VARIABLES
FILE HANDLING IN PYTHON
PYTHON – MODULES
PYTHON – OBJECT ORIENTED
BUILT - IN CLASS ATTRIBUTE
DESTROYING OBJECTS(GARBAGE COLLECTION)
CLASS INHERITANCE
PYTHON – REGULAR EXPRESSION
APPLICATIONS OF PYTHON
CONCLUSION
INTRODUCTION TO PYTHON:-
WHY PYTHON?
Python is an excellent cross- platform language and it works on
different platforms (Windows, Mac, Linux, UNIX, Raspberry Pi,
and so on).
Python has a simple syntax similar to the English language.
Python has syntax similar to English language that allows
developers to write programs with fewer lines than some other
programming languages.
Python can be treated in a procedural way, an object-oriented
way or a functional way.
Python runs on an interpreter system, meaning that code can
be executed as soon as written. This means that proto-typing
can be very quick.
The formation of python syntax is simple and straight forward
which also makes it popular.
Python codes can be run on a wide variety of hardware
platforms having the same interface.
Python is a preferred high-level, server-side programming
language for websites and mobile apps.
For both, new and old developers, Python has managed to stay
a language of choice with ease.
Python is also foraying into Big Data in a significant way.
Characteristics of Python:-
Following are the important characteristics of python programming –
Variable Types:-
Variables are nothing but reserved memory locations to store values.
This means that when you create a variable you reserve some space
in memory. Based on the data types of a variable, the interpreter
allocates memory and decides what can be stored in the reserved
memory. Therefore, by assigning different data types to variables,
you can store integers, decimals or characters in these variables.
Reserved Words:-
The following list shows the Python keywords. These are reserved
words and you cannot use them as constant or variable or any other
identifier names. All the Python keywords contain lowercase letters
only.
and, exec, not, assert, finally, or, break, for, pass, class,
from, print, continue, global, raise, def, if, return, del,
import, try, elif, in, while, else, is, with, except, lambda,
yield.
1. LISTS -
• Ordered collection of data or sequence of values.
• List is also a sequence type— Sequence operations are
applicable
• Supports similar slicing and indexing functionalities as in the
case of strings.
• They are mutable.
• Advantages of a list over a conventional array.
• List have no size or type constraints (no setting restrictions
beforehand)
• They can contain different object types.
• Example-
my_list = [‘one’, ’two’, ‘three’, 4, 5]
len(my_list) would output 5.
2. DICTIONARY-
• Lists are sequences but the dictionaries are mappings.
• They are mapping between a unique key and a value pair.
• 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.
• These mappings may not retain order.
• Constructing the dictionary.
• Accessing object from the dictionary.
• Nesting Dictionaries.
• Basic Dictionary Methods.
• Basic syntax
d = {} empty dictionary will be generated and assign keys and
values to it, like d [‘animal’] = ‘Dog’
d = (‘k1’, ‘v1’, ‘k2’, ‘v2’}
d [‘k1’] outputs ‘v1’
3. TUPLES-
• A tuple is a sequence of immutable python objects.
• Tuples are sequences, just like lists.
• The difference between tuples ad lists are, the tuples cannot be
changed unlike lists and tuples use parentheses, whereas lists
use square brackets.
• Immutable in nature, i.e. they cannot be changed.
• No type restriction
• Indexing and slicing, everything's same like that in strings and
lists.
• Constructing tuples.
• Basic tuple methods:- immutability.
• We can use tuples to present things that shouldn’t change,
such as days of the week, or dates on a calendar, etc.
• We can delete elements from a list by using Del list_name
[index_val].
4. SETS-
• A set contains unique and unordered elements and we can
construct them by using a set() function.
• Convert a list into Set- l=[1,2,3,4,1,1,2,3,6,7]
• k = set(l) k becomes {1,2,3,4,6,7}
• Basic Syntax-
• x=set()
• x.add(1)
• x = {1}
• x.add(1)
• This would make no change in x now.
1. if statements:
An if statement consists of a Boolean expression followed by one
or more statements.
Syntax:-
If true:
Statement (it execute)
If false:
Statement (not execute)
2. if-else statements:
An if statement can be followed by an optional else statement,
which executes when the Boolean expression is False.
Example:-
x=8
r=x%2
if r== 0:
Print(“Even”)
else:
Print(“Odd”)
3. nested-if statements:
An nested-if statements can use one if or else if statement inside
another if or else statement (can be followed by many optional if or
else statement)
Example:-
x=8
r=x%2
if r==0:
print(“Even”)
if x > 5:
print(“Great”)
else :
print(“Not so great!”)
else :
print(“odd”)
PYTHON - LOOPS
In general, statements are executed sequentially. The first statement
in a function is executed first, followed by the second, and so on.
There may be a situation when you need to execute a block of code
several number of times. Programming languages provide various
control structures that allow for more complicated execution path. A
loop statement allows us to execute a statement or group of
statements multiple times.
1. While loop:
Repeats a statement or group of statements while a given
condition is TRUE. It tests the condition before executing the loop
body.
Syntax –
While condition:
We also needs a counter variable i.e. i.
For Example-
i=1 initialization
While i < 3: condition
print(“Hey John ”)
i = i +1 increment
Output:
Hey john
Hey John
Hey John
2. For loop:
Executes a sequence of statements multiple times and abbreviates
the code that manages the loop variable.
Syntax: for i in collection or sequence:
For example:
Output:
11
13
15
17
19
3. Nested loop:
We can use one or more loops inside any another while, for or do
while loop.
For Example:
for i in range(4):
for j in range(4):
print(“#”, end = “ ”)
print()
Output:
# # # #
# # # #
# # # #
# # # #
Python- Numbers
Python supports four different numerical types-
int (signed integers) –
They are often called just integers or ints, are positive or negative
whole numbers with no decimal point.
Indexing-
Strings can be indexed.
First character has index 0.
Negative indices start counting from the right.
Negative indices start from -1.
-1 means last, -2 means second last, and so on.
Slicing-
To obtain a substring
s [start – end] means substring of s starting at index start and
ending at index end -1.
s [0:len(s)] is same as s.
Both start and end are optional -
— If start is omitted, it defaults to 0.
— If end is omitted, it defaults to the length of string.
S[:] is same as s[0: len(s)] – Essentially, a copy of s.
Python Identifiers
A Python identifier is a name used to identify a variable, function,
function, class, module or other object. An identifiers starts with a
letter A to Z or a to z or an underscore (_) followed by zero or more
letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and %
within identifiers. Python is a case sensitive programming language.
Thus, Manpower and manpower are two different identifier in
Python. Here are naming conventions for Python identifiers – class
names start with an uppercase letter. All other identifiers start with a
Class names start with an uppercase letter. All other identifiers start
with a lowercase letter. Starting an identifier with a single leading
underscore indicates that the identifier is private. Starting an
identifier with two leading underscores indicates a strongly private
identifier. If the identifier also ends with two trailing underscores,
the identifier is a language-defined special name.
Python - Function
A function is a block of organized, reusable code that is used to
perform a single, related action. Function provide better modularity
for your application and a high degree or code reusing. As you
already know, python gives us many built- in functions are called
user-defined functions.
Defining a function
We can define functions to provide the required functionally. Here
are simple rules to define a function in Python.
Function blocks begin with the keyword def followed by the
function name and parenthesis { { } }.
Any input parameters or arguments should be placed within
these parenthesis. We can also define parameters inside these
parenthesis.
The first statement of a function can be an optional statement
– the documentation string of the function or docstring.
The code block within every function starts with a colon (:) and
is indented.
The statement return [expression] exits a function, optionally
passing back an expression to the caller. A return statement
with no arguments is the same as return none.
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 we call a function, the variables
declared inside it are brought into scope.
Modules:
As program gets longer, it needs to organize them for easier
access and easier maintenance.
Reuse the same function across programs without copying its
definition into each program.
Python allows putting definitions in a file – use them in a script or
in an interactive instance of the interpreter.
Such a file is called a module – definitions from a module can be
imported into other modules or into the main module.
A module is a file containing Python definitions and statements.
To create a module just save the code that we want in a file with
the file extension ‘.py’
The file name is the module name with the suffix.py appended.
Within a module, the module’s name is available in the global
variable__ name__.
We can create an alias when you import a module, by using the as
keyword.
Example:
def greeting(name)
print(“Hello, ” + name)
Save the following code in a file named mymodule.py
USE A MODULE
Import mymodule
Mymodule.greeting(“Jonathan”)
Class Inheritance
Instead of starting from scratch, you can create a class by deriving it
from a pre-existing class by listing the parent class in parenthesis
after the new class name. The child class inherits the attributes of its
parent class, and you can use those attributes as if they were defined
in the child class. A child class can also override data members and
methods from the parent.
Syntax Derived classes are declared much like their parent class,
however, a list of base classes to inherit from is given after the class
name –
Class Sub-Class Name(Parent class1 [Parent class2…..]):
‘Optional Class documentation string’
Class_suite
You can use issubclass() or isinstance() functions to check a
relationship between two classes and instances. The is subclass (sub,
sup) Boolean function returns true if the given subclass sub is indeed
a subclass of the superclass sup. The is instance (obj, class) Boolean
function return true if obj is an instance of class or is an instance of
subclass of class.
Base overloading methods
1__init__(self[, args…])
Constructor (with any optional arguments)
Sample Call: obj = class Name(args)
2__del__(self)
Destructor, delete an object
Sample Call: del obj
3__repr__(self)
Evaluable string representation
Sample Call: repr(obj)
4__str__(self)
Printable string representation
Sample Call: str(obj)
5__cmp__(self, x)
Object comparison
Sample Call: cmp(obj, x)
Set in regex
[arn]- Returns a match where one of the specified character (a, r, or
n) are present.
[a-n]- Returns a match for any lower case character, alphabetically
between a and n.
[^arn]- Returns a match for any character EXCEPT a, r, and n.
[0123]- Returns a match where any of the specified digits (0, 1, 2, or
3) are present.
[0-9]- Returns a match for any digit between 0 and 9.
[a-z, A-Z]- Returns a match for any character alphabetically between
a and z, lower case OR upper case.
Use of Numpy-
NumPy is a Python package. It stands for 'Numerical Python'. It is a
library consisting of multidimensional array objects and a collection
of routines for processing of array.
Numeric, the ancestor of NumPy, was developed by Jim Hugunin.
Another package Num array was also developed, having some
additional functionalities. In 2005, Travis Oliphant created NumPy
package by incorporating the features of Num array into Numeric
package. There are many contributors to this open source project.
Operations using NumPy Using NumPy, a developer can perform the
following operations −
Mathematical and logical operations on arrays.
Fourier transforms and routines for shape manipulation.
Operations related to linear algebra.
NumPy has in-built functions for linear algebra and random number
generation.
Simple program to create a matrix-
First of all we import numpy package then using this we take input in
numpy function as a list then we create a matrix:
[ [1 6]
[5 2]
[3 45] ]
There is many more function can be perform by using this like that
take sin value of the given value ,print a zero matrix etc. we also take
any image in the form of array.
Use of Pandas-
Pandas is an open-source, BSD-licensed Python library providing high
performance, easy-to-use data structures and data analysis tools for
the Python programming language. Python with Pandas is used in a
wide range of fields including academic and commercial domains
including finance, economics, Statistics, analytics, etc.
Pandas is an open-source Python Library providing high-performance
data manipulation and analysis tool using its powerful data
structures. The name Pandas is derived from the word Panel Data –
an Econometrics from Multidimensional data.
wxWidgets
Kivy – for writing multi-touch applications
Qt via pyqt or pyside
GTK+
Microsoft Foundation Classes through the win32 extensions
Delphi
3. Science and Numeric Applications
This is one of the widespread applications of Python
programming. With its power, it comes as no surprise that
Python finds its place in the scientific community. For this, we
have:
4. Software Development
Software developers make use of Python as a support language.
They use it for build-control and management, testing, and for a
lot of other things:
5. Education
Thanks to its simplicity, brevity, and large community, Python
makes for a great introductory programming language.
Applications of Python programming in education has a huge
scope as it is a great language to teach in schools or even learn
on your own.
6. Business
Python is also a great choice to develop ERP and e-
commerce systems:
Tryton – A three-tier, high-level, general-purpose
application platform.
Odoo – A management software with a range of business
applications. With that, it’s an all-rounder and forms a
complete suite of enterprise-management applications in-
effect.
7. Database Access
With Python, we have:
8.Network Programming
With all those possibilities, how would Python slack in network
programming? It does provide support for lower-level network
programming:
Twisted Python – A framework for asynchronous network
programming. We mentioned it in section 2.
An easy-to-use socket interface
11. Prototyping
Programming in Python is easy when you compare it with other
languages. It has easy syntax and it offers concise solutions for
implementing all types of functionalities. This is the main reason
why Python can be applied in prototyping stages of software
development.
Console-based Applications
Audio or Video-based Applications
Applications for Images
Enterprise Applications
3D CAD Applications
Computer Vision (Facilities like face-detection and color-
detection)
Machine Learning
Robotics
Web Scraping (Harvesting data from websites)
Scripting
Artificial Intelligence
Data Analysis (The Hottest of Python Applications)
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 source code).
• 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 and
varied.
• And most importantly, its clean syntax offers increased
understanding and enjoyment for students.
The training program having three destination was a lot more useful
than staying at one place throughout the whole course. In my
opinion, I have gained lots of knowledge and experience needed to
be successful in great engineering challenge for future.
ACKNOWLEDGEMENT
It is our proud privilege and duty to acknowledge the kind of
help and guidance received from the several peoples in
preparation of this report. It would not have been possible to
prepare this report in this form without their valuable help
cooperation and guidance.