0% found this document useful (0 votes)
359 views39 pages

INDUSTRIAL REPORT On Python

INDUSTRIAL REPORT on python in brief

Uploaded by

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

INDUSTRIAL REPORT On Python

INDUSTRIAL REPORT on python in brief

Uploaded by

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

INDUSTRIAL TRAINING REPORT

ON

“PYTHON”

Submitted in partial fulfillment of the requirement for degree of

BACHELOR OF TECHNOLOGY
in
COMPUTER SCIENCE ENGINEERING
at
ARKA JAIN UNIVERSITY, Jharkhand

Submitted By
PREM KUMAR SINGH
AJU/190266
Under the Guidance of
SUNIL KUMAR
(Trainer , ThinkNEXT TECHNOLOGIES Private Limited)

SCHOOL OF ENGINEERING & I.T,


ARKA JAIN UNIVERSITY, JAMSHEDPUR
2019-2023
**ATTACH CERTIFICATE (Xerox) FROM THE
COMPANY**
DECLARATION BY THE STUDENT

I sincerely declare that:

1. I am the sole writer of this report.

2. The details of training and experience contain in this report describe my involvement
as a trainee in the field of Computer Science Engineering.

3. All the information contains in this report is certain and correct to the knowledge.

Signature:

Name: PREM KUMAR SINGH

Registration No: AJU/190266

Date: 30th September ,2021

iii
CERTIFICATE

This is to certify that the Industrial Training Report titled "PYTHON" in partial fulfillment of
the requirement for the award of the Degree of Bachelor of Engineering in Computer Science
Engineering, submitted to ARKA JAIN University, Jharkhand, is an authentic record of
bonafide industrial training work carried out by Mr. Prem Kumar Singh and submitted under
my supervision/guidance.

Syed Rashid Anwar Mr. Ashwini Kumar


Assistant Professor Assistant Dean
Faculty-Incharge School of Engineering & I.T

Date: 30th September,2021


Place: Jamshedpur

iv
ACKNOWLEDGEMENT

I would like to express my utmost gratitude to the AJU for providing an opportunity to pursue
the engineering training as partial fulfillment of the requirement for the degree of Bachelor of
Technology in Computer Science Engineering. The internship opportunity I had with THINK
NEXT was a great chance for learning and professional development. Therefore, I consider
myself as a very lucky individual as I was provided with an opportunity to be a part of it. I am
also grateful for having a chance to meet so many wonderful people and professionals who led
me through this internship period.

Bearing in mind previous I am using this opportunity to express my deepest gratitude and special
thanks to the Mr. RAMANDEEP KAUR, H.R, THINKNEXT TECHNOLOGIES
(CHANDIGARH) who in spite of being extraordinarily busy with his duties, took time out to
hear, guide and keep me on the correct path and allowing me to carry out my project at their
esteemed organization and extending during the training.

I express my deepest thanks to Mr SUNIL KUMAR, Assistant Engineer, THINKNEXT


TECHNOLOGIES, CHANDIGARH for taking part in useful decision & giving necessary
advice and guidance and arranged all facilities to make life easier. I choose this moment to
acknowledge his contribution gratefully.

I express my deepest thanks to all staffs and employees of THINKNEXT TECHNOLOGIES for
taking part in useful decision & giving necessary advice and guidance and arranged all facilities
to make life easier. I choose this moment to acknowledge their contribution gratefully. I perceive
as this opportunity as a big milestone in my career development. I will strive to use gained skills
and knowledge in the best possible way, and I will continue to work on their improvement, in
order to attain desired career objectives. Hope to continue cooperation with all of you in the
future.
v

ABSTRACT

This report discusses the training program at THINK NEXT TECHNOLOGIES PRIVATE
LIMITATED company. It states the concepts of python programming.

It shows the brief background about the place of training. It mentions some facts about the
department that was responsible for the training program. The report describe about the history,
characteristics, overview and concept of python programming.
vi

TABLE OF CONTENTS

DECLARATION BY THE STUDENT iii


CERTIFICATE iv
ACKNOWLEDGEMENT v
ABSTRACT vi
TABLE OF CONTENTS vii
CHAPTER-1 INTRODUCTION
1.1 Introduction of Training 01
1.2 About Company 02

CHAPTER- 2 PYTHON INTRODUCTION

2.1 History of Python 03


2.2 Versions of Python 04
2.3 Features of Python 04
2.4 Python examples 05
2.5Who uses Python 05

CHAPTER-3 DATATYPES

3.1 Primitive Datatype 06


3.2 Non-Primitive Datatype 06-07

CHAPTER-4 OPERATOR
4.1Arithmetic Operator 08
4.2 Comparision Operator 08
4.3Assignment Operator 09
4.4Bitwise Operator 10
4.5 Special Operator 10
4.6 Membership Operator 10
4.7 Identity Operator 11

CHAPTER-5 Flow of Control


5.1 Conditional Statement 12-14
5.2 Iterative Statement 15
5.3 Transfer Statement 16-17

CHAPTER-6 FUNCTION
6.1Types of Function 18

vii

6.2Defining a Function 19
6.3Calling a Function 19
6.4 Arguments in Function 19-20

CHAPTER-7 OOPS
7.1 Class 21
7.2 Object 21
7.3 Inheritance 22
7.4 Polymorphism 22
7.5 Encapsulation 22

CHAPTER-8.CONSTRUCTORS 23
8.1 Types of Constructor 24

CHAPTER-9 MY SQL CONNECTOR/ PYTHON 25


DEVELOPER GUIDE

PROJECT 26-27

CONCLUSION 28

BIBLIOGRAPHY 29
viii

Chapter-1
Introduction
1.1 INTRODUCTION OF TRAINING

The purpose of industrial training is to provide exposure for the student on practical
engineering fields. Through this exposure, students will have better understandings of
engineering practical in general and sense of frequencies and possible problems. This training
is part of learning process. So the exposure that uplift the knowledge and experience of a
student need to be properly documented in the form of a report. Through this report, the
experience gained can be delivered to their peers. A properly prepared report can facilitate the
presentation of the practical experience in an orderly, precise and interesting manner.

I have chosen python as an training because it will help in many ways. I have chosen my
language course in python and by having little bit knowledge in this subject which help me to
make carrier in this field. During the learning of python the concepts of other languages are
also get cleared as well as, i got new ideas on projects too.

[II.I] Learning outcomes from training

General learning outcomes:

(a)Understanding the principles and practice of python.


(b)Awareness for professional approach to design.
(c)To design, write, compile, execute program in high level language.

Specific learning outcomes:


(a) Be able to implement, compile, test and run program.
(b) Understand how to build the logic in the program.
1

1.2 ABOUT COMPANY

Think NEXT Technologies Private Limited is an ISO 9001:2015 certified Software,


Electronics and CAD/CAM Systems Development Company (MNC) and approved from
Ministry of Corporate Affairs which deals in Web Designing and Development, Mobile Apps
Development, Digital Marketing, College/School ERP Software, University Conferences and
Journals Management, Android/iPhone Mobile Apps development , Cloud Telephony Services,
Bulk SMS, Voice SMS, Tech Smart Classes (Schools), Biometrics Time Attendance, Security
Systems, PLC/SCADA Solutions, Embedded Systems based Electronics Kits and CAD/CAM
Consultancy etc. We have expertise in latest technologies e.g. Smart Card (Contact Type and
Contactless), NFC, Biometrics, Barcode, RFID, SMS, Voice SMS Android, iPhone, Web,
Windows and Mobile based technologies.

Think NEXT offers various 6 Months/3 Months/ 6 Weeks/45 days/Summer Industrial Training
programs for Bachelor in technology and Engineering students, MCA, BCA, Polytechnic
Diploma, Master degree of science (IT), Bachelor degree of Science (IT), MBA, BBA, B. Com
students and job-seekers. Think NEXT offers Industrial Training in the field of
CSE/IT/Electronics (ECE)/Mechanical/ Civil/Electrical/Aeronautical Engineering, Polytechnic
Diploma students. Think NEXT offers best industrial training or summer training in
Chandigarh Mohali Panchkula region to make students industry-ready. Over the years, with its
hard work, dedication, honesty and teamwork, Think NEXT has become the first choice among
students/job-seekers for best 6 months, 6 weeks, summer training in Chandigarh, Mohali.

Course are conducted:


(a) PHP Course
(b) ANDROID
(c) JAVA
(d) Digital marketing course
(e) Web designing
(f) Artificial Intelligence
(g) Python
(h) ML and DL Course
(i) Data Science
(j) Word press course
(k) MS Excel
(l) C and C++

TRAINING DETAILS (WITH TOPICS)


Chapter-2

PYTHON INTRODUCTION

Python is a widely used high-level, general-purpose, interpreted, dynamic programming


language. Its design philosophy emphasizes code readability, and its syntax allows programmers
to express concepts in fewer lines of code than would be possible in languages such as C++ or
Java. The language provides constructs intended to enable clear programs on both a small and
large scale. Python supports multiple programming paradigms, including object-oriented,
imperative and functional programming or procedural styles. It features a dynamic type system
and automatic memory management and has a large and comprehensive standard library. Python
interpreters are available for installation on many operating systems, allowing Python code
execution on a wide variety of systems.

2.1 History of Phython

Python was developed by Guido van Rossum in the late eighties and early nineties at the National
Research Institute for Mathematics and Computer Science in the Netherlands. Python is derived
from many other languages, including ABC, Modula-3, C, C++, Algol-68, SmallTalk, and Unix
shell and other scripting languages. Python is copyrighted. Like Perl, Python source code is now
available under the GNU General Public License (GPL). Python is now maintained by a core
development team at the institute, although Guido van Rossum still holds a vital role in directing
its progress.
3

2.2 Versions of Python

❖ 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
❖ Python 3.7 June 27, 2018
❖ Python 3.8 October 14, 2019

2.3 Features of Python Programming:


• Easy-to-learn: Python has few keywords, simple structure, and a clearly definedsyntax.
This allows the student to pick up the language quickly.
• Easy-to-read: Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain: Python's source code is fairly easy-to-maintain.
A broad standard library: Python's bulk of the library is very portable and crossplatform
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.
• 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.
• Databases: Python provides interfaces to all major commercial databases.
• GUI Programming: Python supports GUI applications that can be created and ported
to many system calls, libraries, and windows systems, such as Windows MFC, Macintosh,
and the X Window system of Unix.
• Scalable: Python provides a better structure and support for large programs than
shellscripting.
4

2.4 Python Examples

• Web and Internet development (e.g., Django and Pyramid frameworks, Flask and Bottle
micro-frameworks)
• Scientific and numeric computing (e.g., SciPy – a collection of packages for the purposes
of mathematics, science, and engineering; Ipython – an interactive shell that features
editing and recording of work sessions)
• Education (it’ s a brilliant language for teaching programming!)
• Desktop GUIs (e.g., wxWidgets, Kivy, Qt)
• Software Development (build control, management, and testing – Scons, Buildbot,
Apache Gump, Roundup, Trac)
• Business applications (ERP and e-commerce systems – Odoo, Tryton)
• Games (e.g., Battlefield series, Sid Meier\’ s Civilization IV…), websites and services
(e.g., Dropbox, UBER, Pinterest , BuzzFeed…)

2.5 Who uses Python


• Python is being applied in real life revenue-generating product by real companies . For
instance
• Google makes extensive use of python in its web search system and employee
Python’ s creator .
• Intel , Cisco , Hewlett – Packed , Seagate , Qualcomm , and IBM use Python for
hardware writing .
• ESRI uses Python as an end-user customization tool for its popular GIS mapping
products .
• The You-Tube video sharing service is largely written in Python .
5

Chapter-3

Data Types

The data type of a variable or object determines which operations can be applied to it. Once a
variable is assigned a data type, it can be used for computations in the program. The best thing
about Python is that the data type doesn’ t need to be defined when declaring a variable. Data
types exist, but the variables are not bound to any of them. Languages that act in this way are
called dynamically typed languages.

3.1 Primitive data types: Data types which are pre-defined and supported by the programming
language.
• Integers – This value is represented by int class. It contains positive or negative whole
numbers (without fraction or decimal). In Python there is no limit to how long an integer
value can be.

• Float – This value is represented by float class. It is a real number with floating point
representation. It is specified by a decimal point. Optionally, the character e or E
followed by a positive or negative integer may be appended to specify scientific
notation.

• Complex Numbers – Complex number is represented by complex class. It is specified


as (real part) + (imaginary part)j. For example – 2+3j

• String Data Types- In python programming, string data types is used to represent
collection of characters. Characters can be any alphabets, digits and special characters.
Example of strings are 'welcome to python', 'hello 123', '@#$$$' etc.

• Boolean Data Types- Data type with one of the two built-in values, True or False.
Boolean objects that are equal to True are truthy (true), and those equal to False are
falsy (false). But non-Boolean objects can be evaluated in Boolean context as well and
determined to be true or false. It is denoted by the class bool.
3.2 Non-Primitive Data types : Data types which are derived from the primitive data types
and offer increased functionality .
• Set :- In Python, Set is an unordered collection of data type that is iterable, mutable and
has no duplicate elements. The order of elements in a set is undefined though it may
consist of various elements.

• Lists : List are just like the arrays, declared in other languages which is a ordered
collection of data. It is very flexible as the items in a list do not need to be of the same
type.

6
• Tuple :- Just like list, tuple is also an ordered collection of Python objects. The only
difference between tuple and list is that tuples are immutable i.e. tuples cannot be
modified after it is created. It is represented by tuple class.

• Array :- A Python Array is a collection of common type of data structures having


elements with same data type. It is used to store collections of data. In Python
programming, an arrays are handled by the “ array” module. If you create arrays using
the array module, elements of the array must be of the same numeric type.
7

Chapter -4
Operators

Operators in general are used to perform operations on values and variables.

4.1 Arithmetic Operators

Arithmetic operators are used with numeric values to perform common mathematical
operations:

Operator Meaning Examples

+ Add two operands or unary x+y+2


plus

- Subtract right operand from x-y-2


the left or unary plus

* Multiply the operands x*y

/ Divide left operand by the x/y


right one (always result into
float)

% Modulus- remainder of the x % y (remainder of x/y)


division of left operand by
the right

// Floor division – division x//y


that result into whole
number adjusted to the left
in the number line
** Exponent – left operand x**y (x to the power y)
raised to the power of right

4.2 Comparison Operators

These operators compare the values on either sides of them and decide the relation among
them. They are also called Relational operators.

Operator Meaning Example

> Greater than - True if left x>y


operand is greater than the
right

< Less than - True if left x<y


operand is less than the right

== Equal to - True if both x==y


operands are equal

!= Not equal to - True if x!=y


operands are not equal

>= Greater than or equal to - x>=y


True if left operand is
greater than or equal to the
right

<= Less than or equal to - True x<=y


if left operand is less than or
equal to the right

4.3 Assignment Operators

Assignment operators are used to assign values to variables:

Operator Example Equivalent to


= x=5 x=5
+= x+= 5 x=x+5
-= x -= 5 x=x-5
*= x *= 5 x=x*5
/= x /= 5 x=x/5
%= x %= 5 x=x%5
//= x //= 5 x=x//5
**= x **=5 x=x**5
&= x &=5 x=x&5
|= x |= 5 x=x | 5
^= x ^= 5 x=x^5
>>= x>>= 5 x=x>>5
<<= x <<= 5 x=x<<5

4.4 Bitwise Operators

Bitwise operators are used to compare (binary) numbers:

Operator Name Description

& Bitwise AND x & y = 0 (0000 0000)

| Bitwise OR x | y = 14 (0000 1110)

~ Bitwise NOT ~x=-11(1111 1110)

^ Bitwise XOR x ^ y =14 (0000 1110)

>> Bitwise right shift x>>2=2 (0000 0010)

<< Bitwise left shift x<<2=40 (0010 1000)

4.5 Special Operator

Python language offers some special types of operator like the identity operator or the
membership operator .

4.6 Membership Operators

Python’ s membership operators test for membership in a sequence, such as strings, lists,
or tuples. There are two membership operators as explained below
Operator Meaning Example

in True if value/variable is 5 in x
found in the sequence

not in True if value/variable is not 5 not in x


found in the sequence

10

4.7 Identity Operators

Identity operators compare the memory locations of two objects.

Operator Meaning Example

is True if the operands are x is true


identical(refer to the same
object)

is not True if the operands are not x is not true


identical(do not refer to the
same object)
11
Chapter-5

Flow of Control

In Python programming, flow control is the order in which statements or blocks of code are executed at
runtime based on a condition.
The flow control statements are divided into three categories :
a. Conditional statements
b. Iterative statements
c. Transfer statements

5.1 Conditional Statement

In Python, condition statements act depending on whether a given condition is true or false. You can execute
different blocks of codes depending on the outcome of a condition. Condition statements always evaluate to
either True or False.

Types of conditional statements:

1. if statement: In control statements, The if statement is the simplest form. It takes a condition and
evaluates to either True or False. If the condition is True, then the True block of code will be
executed, and if the condition is False, then the block of code is skipped, and The controller moves to
the next line.
Syntax:
if condition :
statement 1
statement 2
statement 3

Example

number =7
if number < 10 :
print(number*number)
print('thank you')
Output
49
thank you
[Program finished]
12
2. if-else statement: The if-else statement checks the condition and executes the if block of code when
the condition is True , and if the condition is False, it will execute the else block of code.
Syntax:
if condition :
statement 1
else :
statement 2

Example

x=12
if x%2==0:
print("even")
else :
print("odd")

Output

even

[Program finished]

3. if-elif-else: In Python, the if-elif-else condition statement has an elif blocks to chain multiple
conditions one after another. This is useful when you need to check multiple conditions. With the
help of if-elif-else we can make a tricky decision. The elif statement checks multiple conditions one
by one and if the condition fulfills, then executes that code.
Syntax:
if condition 1:
statement 1
elif condition 2:
statement 2
else :
statement

Example

x=int(input("enter a number :"))


if x==0:
print("zero")
elif x > 0 :
print("positive")
else :
print("negative")
13
Output
enter a number :4
positive

[Program finished]

4. nested-if : In Python, the nested if-else statement is an if statement inside another if-else statement. It
is allowed in Python to put any number of if statements in another if statement. Indentation is the only
way to differentiate the level of nesting. The nested if-else is useful when we want to make a series of
decisions.
Syntax:
if condition_outer:
if condition_inner :
statement of inner if
else:
statement of inner else
statement of outer if
else:
statement of outer else

statement outer if block

Example :

num=15
if num > 0:
if num==0:
print ("zero")
else :
print ("positive")
else :
print("negative")

Output
positive

[Program finished]
14

5.2 Iterative Statement

In Python, iterative statements allow us to execute a block of code repeatedly as long as the condition is
True. We also call it a loop statements.
Python provides us the following two loop statement to perform some actions repeatedly

for loop: Using for loop, we can iterate any sequence or iterable variable. The sequence can be string, list,
dictionary, set, or tuple.

Syntax:
for element in sequence:
body for loop

Example

for i in range(1,10):
print(i)
Output

1
2
3
4
5
6
7
8
9

[Program finished]

while loop: In Python, The while loop statement repeatedly executes a code block while a particular
condition is true. In while loop ,every time the condition is checked at the beginning of the loop , and if it is
true , then loop’ s body gets executed . when the condition became False , the controller comes out of the
block.
Syntax

while condition :
body for the loop
Example

num=10
sum=0
i=1
while i <=num:
sum = sum+i
i=i+1
15

print("sum of first 10 number is",sum)


Output

sum of first 10 number is 55

[Program finished]

5.3 Transfer Statement

In Python, transfer statements are used to alter the program’ s way of execution in a certain manner. For this
purpose, we use three types of transfer statements.

break statement:- The break statement is used inside the loop to exit out of the loop. It is useful when we
want to terminate the loop as soon as the condition is fulfilled instead of doing the remaining iterations. It
reduces execution time. Whenever the controller encountered a break statement, it comes out of that loop
immediately.

Example
for x in range(10):
if x > 6:
print ("stop processing")
break
print(x)
Output

0
1
2
3
4
5
6
stop processing

[Program finished]

continue statement:- The continue statement is used to skip the current iteration and continue with the next
iteration.
Example

for num in range(3,8):


if num==6:
continue
else:
print(num)

16

Output

3
4
5
7

[Program finished]

pass statements:- The pass is the keyword In Python, which won’ t do anything. Sometimes there is a
situation in programming where we need to define a syntactically empty block. We can define that block
with the pass keyword. A pass statement is a Python null statement. When the interpreter finds a pass
statement in the program, it returns no operation. Nothing happens when the pass statement is executed. It is
useful in a situation where we are implementing new methods or also in exception handling. It plays a role
like a placeholder.

Example
months=['january','march','may','june']
for mon in months:
pass
print(months)

Output

['january', 'march', 'may', 'june']

[Program finished]
17

Chapter – 6
Function

A function is a block of code that only runs when it is called. Python functions return a value using a return
statement, if one is specified. A function can be called anywhere after the function has been declared. By
itself, a function does nothing. But, when you need to use a function, you can call it, and the code within the
function will be executed.

Advantages of functions

• Using functions, we can avoid rewriting the same logic/code again and again in a program.
• We can call Python functions multiple times in a program and anywhere in a program.
• We can track a large Python program easily when it is divided into multiple functions.
• Reusability is the main achievement of Python functions.
• However, Function calling is always overhead in a Python program.

6.1 Types of function


• Built in Function :- The built-in functions are those functions that are pre-defined in Python.
• User-defined Function :- The user-defined functions are those define by the user to perform the
specific task.
• Anonymous Function :- These functions are called anonymous because they are not declared in the
standard manner by using the def keyword. You can use the lambda keyword to create small
anonymous functions.
Syntax

The syntax of lambda functions contains only a single statement, which is as follows −
lambda [arg1 [,arg2,.....argn]]:

a. Map function :- The map() function iterates through all items in the given iterable and executes the
function we passed as an argument on each of them.
Syntax
map (function, iterable(s))
We can pass as many iterable objects as we want after passing the function we want to use:

b. Filter function :- Similar to map(), filter() takes a function object and an iterable and creates a new
list. As the name suggests, filter() forms a new list that contains only elements that satisfy a certain
condition, i.e. the function we passed returns True.
Syntax
filter(function, iterable(s))
18

6.2 Defining a function

Defining a function refers to creating the function. This involves writing a block of code that we can call by
referencing the name of our function. A function is denoted by the def keyword, followed by a function
name, and a set of parenthesis.

Rules to define a function:

a. Function blocks begin with the keyword def followed by the function name and parentheses ( ( ) ).
b. Any input parameters or arguments should be placed within these parentheses. You can also define
parameters inside these parentheses.
c. The first statement of a function can be an optional statement - the documentation string of the
function or docstring.
d. The code block within every function starts with a colon (:) and is indented.
e. 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
Syntax

def_ my_function(parameters):
function_block
return expression

6.3 Calling a function


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. Consider the following example of a simple
example that prints the message "Hello World".
Example

Def hello_world():
print("hello world")
# function calling
hello_world()

Output
Hello world

6.4 Argument in function


The arguments are types of information which can be passed into the function. The arguments are specified
in the parentheses. We can pass any number of arguments, but they must be separate them with a comma.
Consider the following example, which contains a function that accepts a string as the argument.
19

Types of arguments

• Required arguments
• Keyword arguments
• Default arguments
• Variable-length arguments

Required Argument

These are the arguments which are required to be passed at the time of function calling with the exact match
of their positions in the function call and function definition. If either of the arguments is not provided in the
function call, or the position of the arguments is changed, the Python interpreter will show the error.

Default argument

Python allows us to initialize the arguments at the function definition. If the value of any of the arguments is
not provided at the time of function call, then that argument can be initialized with the value given in the
definition even if the argument is not specified at the function call.

Variable-length arguments (*args)

In large projects, sometimes we may not know the number of arguments to be passed in advance. In such
cases, Python provides us the flexibility to offer the comma-separated values which are internally treated as
tuples at the function call. By using the variable-length arguments, we can pass any number of arguments.
However, at the function definition, we define the variable-length argument using the *args (star) as
*<variable - name >.

Keyword argument (**kwargs)

Python allows us to call the function with the keyword arguments. This kind of function call will enable us to
pass the arguments in the random order.
The name of the arguments is treated as the keywords and matched in the function calling and definition. If
the same match is found, the values of the arguments are copied in the function definition.
20

Chapter- 7
OOPS
Object-oriented programming (OOP) is a computer programming model that organizes software design
around data, or objects, rather than functions and logic. An object can be defined as a data field that has
unique attributes and behavior.

OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate
them. This approach to programming is well-suited for programs that are large, complex and actively
updated or maintained. This includes programs for manufacturing and design, as well as mobile applications;
for example, OOP can be used for manufacturing system simulation software.

Characteristics of OOPS
• Objects
• Class
• Data Hiding
• Data Abstraction
• Encapsulation
• Polymorphism

7.1 Class
A class is a collection of objects. A class contains the blueprints or the prototype from which the objects are
being created. It is a logical entity that contains some attributes and methods.

Some points on Python class:


1. Classes are created by keyword class.
2. Attributes are the variables that belong to a class.
3. Attributes are always public and can be accessed using the dot (.) operator. Eg.: Myclass.Myattribute
Syntax
class Classname:
#statement
.
.
.
#statement - N
7.2 Object
The object is an entity that has a state and behavior associated with it. It may be any real-world object like a
mouse, keyboard, chair, table, pen, etc. Integers, strings, floating-point numbers, even arrays, and
dictionaries, are all objects.

21

Creating an object
obj = Dog()

This will create an object named obj of the class Dog defined above. Before diving deep into objects and
class let us understand some basic keywords that will we used while working with objects and classes.

7.3 Inheritance
Inheritance is the capability of one class to derive or inherit the properties from another class. The class that
derives properties is called the derived class or base class and the class from which the properties are being
derived is called the base class or parent class.

The benefits of inheritance are:

1. It represents real-world relationships well.


2. It provides the reusability of a code. We don’ t have to write the same code again and again. Also, it
allows us to add more features to a class without modifying it.
3. It is transitive in nature, which means that if class B inherits from another class A, then all the
subclasses of B would automatically inherit from class A.

7.4 Polymorphism
Polymorphism simply means having many forms. For example, we need to determine if the given species of
birds fly or not, using polymorphism we can do this using a single function.

7.5 Encapsulation
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It describes the
idea of wrapping data and the methods that work on data within one unit. This puts restrictions on accessing
variables and methods directly and can prevent the accidental modification of data. To prevent accidental
change, an object’ s variable can only be changed by an object’ s method. Those types of variables are
known as private variables. A class is an example of encapsulation as it encapsulates all the data that is
member functions, variables, etc.
22

Chapter -8
Constructor

A constructor is the first method that is called on object creation (a concept from Object Orientated
Programming). It is always part of a class (an objects methods are defined in a class). The constructor is
always called when creating a new object. It can be used to initialize class variables and startup routines. The
constructor allows you to set variables for the object immediately.Each class can contain one and only one
constructor.
The constructor is always named def __init__(self):.

There are a few rules for constructors:

1. A constructor must be defined with the name __init__.


2. A constructor must be defined with the self keyword in its parameters.
3. A constructor cannot return any value, except None.
4. Only one constructor is allowed for a class.
5. Only for object initialization
Example
class Employee:
def __init__(self, name, id):
self.id = id
self.name = name

def display(self):
print("ID: %d \nName: %s" % (self.id, self.name))

emp1 = Employee("John", 101)


emp2 = Employee("David", 102)
# accessing display() method to print employee 1 information

emp1.display()

# accessing display() method to print employee 2 information


emp2.display()

23
Output
ID: 101
Name: John
ID: 102
Name: David

8.2 Types of constructor


Non-Parameterized Constructor: The non-parameterized constructor uses when we do not want to
manipulate the value or the constructor that has only self as an argument. Consider the following example.

Parameterized Constructor : The parameterized constructor has multiple parameters along with the self.
Consider the following example
.
Python Default Constructor

When we do not include the constructor in the class or forget to declare it, then that becomes the default
constructor. It does not perform any task but initializes the objects. Consider the following example.
24
Chapter-9

MySQL Connector/Python Developer Guide

MySQL is one of the most popular database management systems (DBMSs) on the market today. It ranked
second only to the Oracle DBMS in this year’ s DB-Engines Ranking. As most software applications need to
interact with data in some form, programming languages like Python provide tools for storing and accessing
these data sources.

Using the techniques discussed in this tutorial, you’ ll be able to efficiently integrate a MySQL database with
a Python application. You’ ll develop a small MySQL database for a movie rating system and learn how to
query it directly from your Python code.

• Identify unique features of MySQL


• Connect your application to a MySQL database
• Query the database to fetch required data
• Handle exceptions that occur while accessing the database
• Use best practices while building database applications

To get the most out of this tutorial, you should have a working knowledge of Python concepts
like for loops, functions, exception handling, and installing Python packages using pip. You should also have
a basic understanding of relational database management systems and SQL queries
like SELECT, DROP, CREATE, and JOIN.
25

Project (Calculator)

from tkinter import *

root = Tk()
root.title(“ CALCULATOR” )

def show(n):
global exp
exp = exp+n
st.set(exp)

def calculate():
global exp
rs = eval(exp)
st.set(rs)

exp = ""
st = StringVar()

txt = Entry(root, textvariable = st).grid(row = 0, column = 0, columnspan = 6)

btn = Button(root, text = "C").grid(row = 1, column = 1)


btn = Button(root, text = "+-").grid(row = 1, column = 2)
btn = Button(root, text = "%", command = lambda:show("%")).grid(row = 1, column = 3)
btn = Button(root, text = "/", command = lambda:show("/")).grid(row = 1, column = 4)

btn = Button(root, text = "9", command = lambda:show("9")).grid(row =2, column = 1)


btn = Button(root, text = "8", command = lambda:show("8")).grid(row = 2, column = 2)
btn = Button(root, text = "7", command = lambda:show("7")).grid(row = 2, column = 3)
btn = Button(root, text = "", command = lambda:show("")).grid(row = 2, column = 4)
btn = Button(root, text = "6", command = lambda:show("6")).grid(row =3, column = 1)
btn = Button(root, text = "5", command = lambda:show("5")).grid(row = 3, column = 2)
btn = Button(root, text = "4", command = lambda:show("4")).grid(row = 3, column = 3)
btn = Button(root, text = "+", command = lambda:show("+")).grid(row = 3, column = 4)

btn = Button(root, text = "3", command = lambda:show("3")).grid(row =4, column = 1)


btn = Button(root, text = "2", command = lambda:show("2")).grid(row = 4, column = 2)
btn = Button(root, text = "1", command = lambda:show("1")).grid(row = 4, column = 3)
btn = Button(root, text = "0", command = lambda:show("0")).grid(row = 4, column = 4)

26

btn = Button(root, text = ".", command = lambda:show(".")).grid(row =5, column = 1)


btn = Button(root, text = "<-").grid(row = 5, column = 2)
btn = Button(root, text = "=", command = lambda:calculate()).grid(row = 5, column = 3)
btn = Button(root, text = "^").grid(row = 5, column = 4)

root.mainloop()

OUTPUT
27

Conclusion
We tackled the basics of the Python programming language. This approach should be enough to understand all
the following Python examples. We came across data types ,operators, functions, loops, conditional statement,
constructors and many more which is quiet similar to C, C++ and JAVA .

Trouble shooting of the python code was much easier and understandable. The code was bit easier as no. of
lines was short as compared to other programming languages.

Python is easily readable and maintainable across a wide chain of developers. It is so because it has kicked
one step higher to the programming paradigm. The code which is written resembles plain English and can
be understood even by beginner programmers. It also helps to update the code easily from time to time and
invest less effort in doing so. Python supports both function-oriented and structure-oriented programming. It
has features of dynamic memory management which can make use of computational resources efficiently. It
is also compatible with all popular operating systems and platforms. Hence this language can be universally
accepted by all programmers. Python supports a large built-in library from which we can extract any feature
to implement in the form of packages. Thus it enables us to implement a feature without writing excess code.

While working on project, we learn many aspects related python which we’ ll follow in further projects too.
28

Bibliography
REFRENCES :

1. https://www.guru99.com/python-arrays.html
2. https://pynative.com/python-control-flow-statements/
3. https://www.javatpoint.com/python-functions
4. https://www.geeksforgeeks.org/python-oops-concepts/
5. https://pythonprogramminglanguage.com/constructor/
29

You might also like