0% found this document useful (0 votes)
36 views53 pages

Shalvi Python Internship Report - Word

This internship training report on 'Python Programming Language' provides an overview of Python's history, characteristics, features, and various programming concepts including data structures, operators, decision making, and loops. It highlights Python's ease of use, portability, and support for multiple programming paradigms. The document serves as a comprehensive guide for students pursuing a Bachelor of Technology in Computer Science and Engineering.

Uploaded by

shubham191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views53 pages

Shalvi Python Internship Report - Word

This internship training report on 'Python Programming Language' provides an overview of Python's history, characteristics, features, and various programming concepts including data structures, operators, decision making, and loops. It highlights Python's ease of use, portability, and support for multiple programming paradigms. The document serves as a comprehensive guide for students pursuing a Bachelor of Technology in Computer Science and Engineering.

Uploaded by

shubham191
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 53

ELECTRONICS & ICT ACADEMY, IIT KANPUR

INTERNSHIP TRAINING REPORT

ON

“PYTHON PROGRAMMING LANGUAGE”

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”

SUBMITTED TO: SUBMITTED BY:


ER.AMIT GUPTA SHALVI PUNDIR (1808310045)

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


S.D.COLLEGE OF ENGINEERING & TECHNOLOGY
MUZAFFARNAGAR (U.P.)-251001
(2020-2021)
Python Releases
 Python 1.0 - January 1994
 Python 1.5 - December 31,
1997
 Python 1.6 - September 5, 2000
 Python 2.0 - October 16, 2000
 Python 2.1 - April 17, 2001
 Python 2.2 - December 21,
2001
 Python 2.3 - July 29, 2003
 Python 2.4 - November 30,
2004
 Python 2.5 - September 19,
2006
 Python 2.6 - October 1, 2008
 Python 2.7 - July 3, 2010
 Python 3.0 - December 3, 2008
 Python 3.1 - June 27, 2009
 Python 3.2 - February 20, 2011
 Python 3.3 - September 29,
2012
 Python 3.4 - March 16, 2014
 Python 3.5 - September 13,
2015
 Python 3.6 - December 23,
2016

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:-

Python is a general-purpose interpreted, interactive, object-oriented,


and high-level programming language. It was created by Guido van
Rossum during 1985-1990 and released in 1991. Python has syntax
similar to English language that allows developers to write programs
with fewer lines than some other programming languages. Python
runs on an interpreter system, meaning that code can be executed as
soon as written. This means that prototyping can be very quick.

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 –

 Python is a dynamic, high-level, free open source and interpreted


programming language.
 It supports object-oriented programming as well as procedural
oriented programming.
 It can be used as a scripting language or can be compiled to byte-
code for building large applications.
 It provides very high-level dynamic data types and supports
dynamic type checking.
 It supports automatic garbage collection.
 It can be easily integrated with C, C++, COM, ActiveX, CORBA, and
Java.
Features of python:-
• Interpreted Language: Python is an interpreted language because
python code is executed line by line at a time. Like other languages C,
C++, java, etc. there is no need to compile python code this makes it
easier to debug our code. The source code of python is converted
into an immediate form called byte code.

• Easy to code: Python is a High-level programming language and it is


very easy to learn as compared to other languages like C, C#, Java
script, Java, etc. It is very easy to code in Python language and it is
also a developer friendly language.

• Portable: Python language is also a portable language. For


example, if we have python code for windows and if we want to run
this code on other platform such as Linux, UNIX, and Mac then we do
not need to change it, we can run this code on any platform.
• Extensible: Python is an extensible language. We can write us some
Python code into C or C++ language and also we can compile that
code in C/C++ language.

• GUI Programming Support: Graphical user interfaces can be made


using a module such as PyQt5, PyQt4, wx-Python, or Tk in python.
PyQt5 is the most popular option for creating graphical apps with
python.

• Scalable: Python provides an improved structure for supporting


large programs than shell-scripts.

• Integrated Language: Python is also an integrated language


because we can easily integrated python with other languages like c,
c++, etc.

• Object-Oriented Language: One of the key features of python is


object-oriented programming. It supports object-oriented language
and concept of classes, objects encapsulation, etc.

• Interactive Programming Language: Python has support for an


interactive mode which allows interactive testing and debugging of
snippets of code. Users can interact with the python interpreter
directly for writing programs.

• Easy language: Python is very easy to learn the language as


compared to other languages like C, C#, Java script, Java, etc. Python
is easy to learn language especially for beginners.

• Dynamically Typed Language: Python is a dynamically – typed


language. That means the type (for example – int, double, long, etc.)
for a variable is decided at run time not in advance because of this
feature we don’t need to specify the type of variable.
• Large Standard Library: Python has a large standard library which
provides a rich set of module and function so you do not have to
write your own code for every single thing. There are many libraries
present in python for such as regular expressions, unit-testing, web
browsers, etc.

• Straight forward Syntax: The formation of python syntax is simple


and straight forward which also makes it popular.

• Free and Open Source: Python language is freely available at the


official website and you can download it from the given download
link below click on the Download Python keyword.
Since it is open-source, this means that source code is also available
to the public. So you can download it as, use it as well as share it.

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.

Assigning Values to Variables:-

Python variables do not need explicit declaration to reserve memory


space. The declaration happens automatically when you assign a
value to a variable. The equal sign (=) is used to assign values to
variables. The operand to the left of the (=) operator is the name of
variable and the operand to the right of the (=) operator is the value
stored in the variable.
counter = 1 # An integer assignment
millers = 1100000.00 # A floating point
name = “John” # A string

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.

Data Structure in Python:-


The data stored in memory can be of many types. For example, a
person’s age is stored as a numeric value and his or her address is
stored as alphanumeric characters. Python has various standard data
types that are used to define the operations possible on them and
the storage method for each of them. Python has different standard
data types such as-

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].

Built-in Tuple Functions:-


1. cmp(tuple1, tuple2) Compares elements of both tuples.
2. len(tuple) Gives the total length of the tuple.
3. max(tuple)Returns item from the tuple with max value.
4. min(tuple)Returns item from the tuple with the min value.
5. tuple(seq)Converts a list into tuple.

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.

Python – Basic Operators


Operators are the constructs which can manipulate the value of
operands. Or Operators are the special symbol which performs
operation on two or more operands.

Consider a mathematical expression 4 + 5 = 9.


Here, ‘4’ and ‘5’ are called operands and ‘+’ and ‘=’ is called
operators.
Python language supports the following types of operators:-
1. Arithmetic Operators[+, -, *, /, %]
2. Assignment Operator[=]
3. Relational or Comparison Operators [>, <, ==, >=, <=, !=]
4. Logical Operators[and, or, not]
5. Bitwise Operators[~, &, |, ^, <<, >>]
6. Identity Operators

Python – Decision Making

Decision making is anticipation of conditions occurring while


execution of the program and specifying action taken according to
the conditions. Decision structures evaluated multiple expressions
which produce TRUE or FALSE as outcome. You need to determine
which action to take and which statements to execute if the outcome
is TRUE or FALSE otherwise.
Python programming language assumes any non-zero and non-null
values as TRUE, and if it is either zero or null, then it is assumed as
FALSE value. The Python programming language provides the
following types of decision making statements.

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)

If basically a block or in python it is a suite (where you can


write multiple statement).
In if-statement we follow the proper indentation to write a
code.
Example:-
X = int(input(“enter any number”))
if x>0:
print(“Positive Number”)
if x<0:
print(“Negative Number”)
if x==0:
print(“Zero”)

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:

for i in range (11, 21,2)


print(i)

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.

long (long integers) –


Also called longs, they are integers of unlimited size written like
integers and followed by an uppercase or lowercase.

Float (floating point real values) –


Also called floats, they represents real numbers and are written with
a decimal point dividing the integer and fractional parts. Float may
also be in scientific notation with E or e indicating the power of 10.
For example – 2.5 e 2 = 2.5 x 10 = 250.

Complex (complex numbers)—


Complex numbers are in the form of a + ij where a and b are floats
and j represents the square root of -1 (which is an imaginary
number). The real part of the number is a, and the imaginary part is
b. Complex numbers are not used much in Python programming.

Number Type conversion


Python converts numbers internally in an expression containing
mixed types to a common type for evaluation. But sometimes, we
need to coerce a number explicitly from one type to another to
satisfy the requirements of an operator or function parameter.

 Type int(x) to convert x to a plain integer.


 Type long(x) to convert x to a long integer.
 Type float(x) to convert x to a floating-point number.
 Type complex(x) to convert x to a complex number with
real part x and imaginary part zero.
Python – Strings
Strings are amongst the most popular types in python. We can create
them simply by enclosing characters in quotes. Python treats single
quotes the same as double quotes. Creating strings is as simple as
assigning a value to a variable.
For example –
var1 = “Hello World!”
var2 = “Python Programming”

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 string in-built method-


1 Capitalize () capitalizes first letter of string.

2 Center (width, fillchar) Returns a space-padded string with the


original string centered to a total of width columns.

3 Count (str, beg=0, end-len(string)) counts how many times str


occurs in string or in a substring of string if starting index beg and
ending index end are given.

4 Isalnum() Returns true if string has at least 1 character and all


characters are alphanumeric and false otherwise.

5 Isalpha () Returns true if string has at least 1 character and all


characters are alphabetic and false otherwise.

6 Isdigit () Returns true if string contains only digits and false


otherwise.
7 Islower () Returns true if string has at least 1 cased character and
all cased characters are in lowercase and false otherwise.

8 Isnumeric () Returns true if a Unicode string contains only


numeric characters and false otherwise.
9 Isspace () Returns true if string contains only whitespace
characters and false otherwise.

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.

Rules of Identifiers in Python


So we know what a Python Identifier is. But can we name it
anything? Or do certain rules apply? Well, we do have five rules to
follow when naming identifiers in Python:
a. A Python identifier can be a combination of lowercase/ uppercase
letters, digits, or an underscore. The following characters are valid:
Lowercase letters (a to z)
Uppercase letters (A to Z)
Digits (0 to 9)
Underscore (_)
Have a look at Python Number Types
some valid names are:
myVar
var_3
this_works_too
b. An identifier cannot begin with a digit.
Some valid names:
_9lives
lives9
An invalid name:
9lives

Identifiers in Python – Naming Rules


c. We cannot use special symbols in the identifier name. Some of
these are:
!
@
#
$
%
.

Identifiers in Python – Naming Rules in Python


d. We cannot use a keyword as an identifier. Keywords are reserved
names in Python and using one of those as a name for an identifier
will result in a Syntax Error.
Identifiers in Python – Identifiers Naming Rules

Naming Rules in Python Identifiers

An identifier can be as long as you want. According to the docs, you


can have an identifier of infinite length. However, the PEP-8 standard
sets a rule that you should limit all lines to a maximum of 79
characters.

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.

def function name (parameters):


“ function_docstring”
Function_suite
Return[expression]

The Return Expression:The statement return [expression] exists


a function, optionally passing back an expression to the caller. A
return statement with no arguments is the same as return none.
Scope of variables

All variables I 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 –
1. Global variables
2. Local variables

Global vs. Local variables

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.

File handling in Python


Python too supports file handling and allows users to handle files i.e.,
to read and write files, along with many other file handling options,
to operate on files. The concept of file handling has stretched over
various other languages, but the implementation is either
complicated or lengthy, but alike other concepts of Python, this
concept here is also easy and short. Python treats file differently as
text or binary and this is important. Each line of code includes a
sequence of characters and they form text file. Each line of a file is
terminated with a special character, called the EOL or End of Line
characters like comma {,} or newline character. It ends the current
line and tells the interpreter a new one has begun. Let’s start with
Reading and Writing files.
File I/O:-
We use open () function in Python to open a file in read or write
mode. As explained above, open ( ) will return a file object. To return
a file object we use open () function along with two arguments, that
accepts file name and the mode, whether to read or write. So, the
syntax being: open(filename, mode).
 Files are persistent storage.
 Allow data to be stored beyond program lifetime
 The basic operations on files are – open, close, read, write,
append.
 Python treat files as sequence of lines-sequence operations work
for the data read from files.

File I/O: open and close open(filename, mode) File I/O:


read , write and append
 While opening a file, you need to supply– The name of the file,
including the path – The mode in which you want to open a file
—Common modes are r(read), w(write), a(append).
 Mode is optional, defaults to r
 Open(..) returns a file object
 Close() on the file object closes the file— finishes any buffered
operations.

File I/O: read, write and append


 Reading from an open file returns the content of the file –as
sequence of lines in the program.
 Writing to a file –If opened with mode ‘w’ , clears the existing
contents of the file – Use append mode(‘a’) to preserve the
contents- Writing happens at the end.

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

Now we can use the module we just created, by using the


import statement:

Import mymodule
Mymodule.greeting(“Jonathan”)

Output: Hello, Jonathan

The import statement:


You can use any python source file as a module by executing an
import statement in some other Python source file. The import has
the following syntax – “import module”.

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.

The from….import statement-


Python’s from statement lets you import specific attributes from a
module into the current namespace.

Python – Object Oriented


Python has been an object- oriented language since it existed.
Because of this, creating and using classes and objects are downright
easy. This chapter helps us become an expert in using Python’s
object-oriented programming support. If you do not have any
previous experience with object- oriented programming (OOPS), we
may want to consult an introductory course on it or at least a tutorial
of some sort so that you have a grasp of the basic concepts.
However, here is a small introduction of object-oriented
programming (OOP) to bring you at speed –
Overview of OOP Terminology:

 Class – A user-define prototype for an object that defines a


set of attributes that characterize any object of the class. The
attributes are data members (class variables and instance
variables () and methods, accessed via dot notation.
 Class variable – A variable that is shared by all instances of a
class. Class variable are defined within a class but outside any
of the class’s methods. Class variable are not used as
frequently as instance variable are.
 Data member – A class variable or instance variable that
holds associated with a class and its object.
 Function overloading – The assignment of more than one
behavior to a particular function. The operation performed
varies by the types of objects or arguments involved.
 Instance variable – A variable that is defined inside a method
and belongs only to the current instance of a class.
 Inheritance – The transfer of the characteristics of a class to
the other classes that are derived from it.
 Instance – An individual object of a certain class. An object
obj that belongs to a class circle, for example, is an instance of
the class Circle.
 Instantiation – The creation of an instance of a class.
 Method – A special kind of function that is defined in a class
definition.
 Object – A unique instance of a data structure that’s defined
by its class. An object comprises both data members (class
variables and instance variables) and methods.
 Operator overloading – The assignment of more than one
function to a particular operator.

Built-in Class Attributes:


Every Python class keeps following built- in attributes and they can
be accessed using dot operator or dot notation like any other
attribute.
__dict__ - Dictionary containing the class’s namespace.
__doc__ - Class documentation string or none, if undefined.
__name__ - Class name.
__module__ - Module name in which the class is defined. This
attribute is “__main__” in interactive mode.
__bases__ - A possibly empty tuple containing the base classes, in
the order of their occurrence in the base class list.

Destroying Objects (Garbage Collection)


Python deletes unneeded objects (built-in types or class instances)
automatically to free the memory space. The process by which
python periodically reclaims blocks of memory that no longer are in
use is termed Garbage Collection. Python’s garbage collector runs
during program execution and is triggered when an object’s
reference count reaches zero. An object’s reference count increases
when it is assigned a new name or placed in a container (list, tuple,
or dictionary). The object’s reference count decreases when it’s
deleted with del, its reference is reassigned, or its reference goes out
of scope. When an object’s reference count reaches zero, Python
collects it automatically.

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)

Python – Regular Expressions


A regular expression is a special sequence of characters that helps
you match or find other strings or sets of strings, using a specialized
syntax held in a pattern. Regular expressions are widely used in the
UNIX. The Python re module provides full support for Perl-like
regular expressions in Python. The re module raise the exception
re .error if an error occurs while compiling or using a regular
expression. We would cover two important functions, which would
be used to handle regular expressions. But a small thing first: There
are various characters, which would be special meaning when they
are used in regular expression. To avoid any confusion while dealing
with the regular expressions, we would use raw strings as r
’expression’.
RegEx function -
find all- Returns a list containing all matches.
search – Returns a Match object if there is a match anywhere in the
string.
split – Returns a list where the string has been split each match.
Sub – Replaces one or many matches with a string.

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:

Import numpy as np:


b=np.array ([[1,6,,5,2,3,45]])
b .shape = (3,2)
print(b)

[ [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.

Key Features of Pandas-


• Fast and efficient Data Frame object with default and customized
indexing.
• Tools for loading data into in-memory data objects from different
file formats.
• Data alignment and integrated handling of missing data.
• Reshaping and pivoting of date sets.
• Label-based slicing, indexing and sub setting of large data sets.
• Columns from a data structure can be deleted or inserted.
• Group by data for aggregation and transformations.

Pandas deals with the following three data structures −


1. Series
2. Data Frame
3. Panel
These data structures are built on top of Numpy array, which means
they are fast.
Applications of Python
These are some real-world Python applications:

 Web and Internet Development


 Desktop GUI Applications
 Science and Numeric
 Software Development
 Education
 Database Access
 Network Programming
 Games and 3D Graphics
Let’s discuss each of them in detail:

1. Web and Internet Development


Python lets you develop a web application without too much
trouble. It has libraries for internet protocols like HTML and
XML, JSON, e-mail processing, FTP, IMAP, and easy-to-use
socket interface. Yet, the package index has more libraries:

Requests – An HTTP client library


BeautifulSoup – An HTML parser
Feedparser – For parsing RSS/Atom feeds
Paramiko – For implementing the SSH2 protocol
Twisted Python – For asynchronous network programming
We also have a gamut of frameworks available. Some of these
are- Django, Pyramid. We also get micro-frameworks like flask
and bottle.

2. Desktop GUI Applications


Most binary distributions of Python ship with Tk, a standard GUI
library. It lets you draft a user interface for an application. Apart
from that, some toolkits are available:

 wxWidgets
 Kivy – for writing multi-touch applications
 Qt via pyqt or pyside

And then we have some platform-specific toolkits:

 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:

 SciPy – A collection of packages for mathematics, science,


and engineering.
 Pandas– A data-analysis and - modeling library
 IPython – A powerful shell for easy editing and recording of
work sessions. It also supports visualizations and parallel
computing.
 Also, NumPy enables us to deal with complex numerical
calculations.

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:

 SCons – for build-control


 Buildbot, Apache Gump – for automated and continuous
compilation and testing
 Roundup, Trac – for project management and bug-
tracking.
 The roster of Integrated Development Environments

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:

 Custom and ODBC interfaces to MySQL, Oracle,


PostgreSQL, MS SQL Server, and others. These are freely
available for download.
 Object databases like Durus and ZODB
 Standard Database API

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

9. Games and 3D Graphics


Safe to say, this one is the most interesting. When people hear
someone say they’re learning Python, the first thing they get
asked is – ‘So, did you make a game yet?’
PyGame, PyKyra are two frameworks for game development with
Python. Apart from this, we also get a variety of 3D-rendering
libraries.

If you’re one of those game-developers, you can check out


PyWeek, a semi-annual game programming contest.

10. Artificial Intelligence and Machine


Learning
The IT industry went far beyond science fiction ideas, and our
future is moving towards Artificial Intelligence. People are keen
to move to technologies where machines can mimic human
behaviours, and machines are automating most of the human
work. There is also a need to process and analyze huge volumes
of data.

Statistically speaking that Python is the most popular language


for Artificial intelligence and Machine Learning.

The several libraries and frameworks for Artificial intelligence


are listed below.
 Tensorflow
 Scikit-learn
 NLTK
 Caffee
 PyTorch
 Keras
 Pandas
 Accord.NET

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.

With many functionalities to offer, Python lets you develop a


prototype of applications faster. Many organizations and firms
use Python at the prototyping stage of a project.

Other Python Applications:


These are some of the major Python Applications. Apart from
what we just discussed, it still finds use in more places:

 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.

First and foremost, I would like to thanks Prof. Amey


karkare for his constant support and encouragement towards
the course and for making available library and laboratory
facilities needed to prepare this report.

The course on “Python Programming Language” was very


helpful to us in giving a great knowledge about python
programming and their contribution and technical support in
preparing this report are greatly acknowledged.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy