Department of Electronics & Communication Engineering
KIPM-College of Engineering and Technology, GIDA, Gorakhpur (273209)
(Affiliated to Dr. A.P.J. Abdul Kalam Technical University, Uttar Pradesh)
(2019-2020)
A
REPORT ON SUMMER TRAINING
BASED ON
PYTHON PROGRAMMING LANGUAGE
Submitted by Submitted to
Aditi Shukla Mr. Bhasker Pandey
(1875137002) (HOD)
(Electronics And Communication)
1
ACKNOWLEDGEMENT
It is my proud privilege and duty to acknowledge the kind of help and guidance
received from several people 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.
This report document and the work done during the summer training in Python
Programming under the supervision of Mr. Rashid Ali who gave me an
opportunity to take professional training in CYL Tech. Lab (Affiliated to E-max
India), Rustampur, Gkp.
I would like to express deep gratitude to Mr. Bhaskar Pandey, Head of
Department (Electronics and Communication), KIPM college of Engineering and
Technology, Gkp without whose permission the training was not possible.
I have tried my best to keep report simple yet technically correct. I hope I succeed
in my attempt.
2
Table of Contents
CHAPTER 1. Introduction
1.1 Python
1.2 History
1.3 Python Versions
1.4 Installation of Python
CHAPTER 2. Basic Data Types
2.1 Integers
2.2 Floating Point Numbers
2.3 Complex Numbers
2.4 Strings
2.5 Bolean type
CHAPTER 3. Python Operators
3.1 Arithmetic Operators
3.2 Comparison Operators
3.3 Assignment Operators
3.4 Logical Operators
3.5 Membership Operators
3.6 Identity Operators
3.7 Summary
CHAPTER 4. Lists in Python
4.1 Python Lists
4.2 Accessing Values in Python
CHAPTER 5. Loops in Python
5.1 If statement
5.2 If…else statement
5.3 If…elif…else statement
5.4 Nested if statement
3
CHAPTER 6.
6.1 Advantages of Python
6.2 Disadvantages of Python
6.3 Conclusion
4
INTRODUCTION
Python is an interpreted, high-level, general-purpose programming language. Created
by Guido van Rossum and first released in 1991, Python's design philosophy
emphasizes code readability with its notable use of significant whitespace. Its
language constructs and object-oriented approach aim to help programmers write
clear, logical code for small and large-scale projects.
Python is dynamically typed and garbage-collected. It supports multiple programming
paradigms, including procedural, object-oriented, and functional programming.
Python is often described as a "batteries included" language due to its
comprehensive standard library.
Python was conceived in the late 1980s as a successor to the ABC language.
Python 2.0, released 2000, introduced features like list comprehensions and a garbage
collection system capable of collecting reference cycles. Python 3.0, released 2008,
was a major revision of the language that is not completely backward-compatible, and
much Python 2 code does not run unmodified on Python 3. Due to concern about the
amount of code written for Python 2, support for Python 2.7 (the last release in the 2.x
series) was extended to 2020. Language developer Guido van Rossum shouldered sole
responsibility for the project until July 2018 but now shares his leadership as a
member of a five-person steering council.
Python interpreters are available for many operating systems. A global community of
programmers develops and maintains C Python, an open source reference
implementation. A non-profit organization, the Python Software Foundation, manages
1and directs resources for Python and C Python development.
1
HISTORY
Python was conceived in the late 1980s by Guido van Rossum at Centrum Wiskunde
& Informatica (CWI) in the Netherlands as a successor to the ABC language (itself
inspired by SETL), capable of exception handling and interfacing with
the Amoeba operating system. Its implementation began in December 1989.[35] Van
Rossum continued as Python's lead developer until July 12, 2018, when he announced
his "permanent vacation" from his responsibilities as Python's Benevolent Dictator
For Life, a title the Python community bestowed upon him to reflect his long-term
commitment as the project's chief decision-maker. In January, 2019, active Python
core developers elected Brett Cannon, Nick Coghlan, Barry Warsaw, Carol Willing
and Van Rossum to a five-member "Steering Council" to lead the project.
Python 2.0 was released on 16 October 2000 with many major new features, including
a cycle-detecting garbage collector and support for Unicode.
Python 3.0 was released on 3 December 2008. It was a major revision of the language
that is not completely backward-compatible. Many of its major features were back
portfolio Python 2.6.x and 2.7.x version series. Releases of Python 3 include
the 2to3 utility, which automates (at least partially) the translation of Python 2 code
to Python 3.
Python 2.7's end-of-life date was initially set at 2015 then postponed to 2020 out of
concern that a large body of existing code could not easily be forward-ported to
Python 3. In January 2017, Google announced work on a Python 2.7
to transcompiler to improve performance under concurrent workloads.
ROSSOM
2
PYTHON VERSIONS
3
INSTALLATION OF PYTHON
Step 1: Download the Python 3 Installer
1. Open a browser window and navigate to the Download page for
Windows at python.org.
2. Underneath the heading at the top that says Python Releases for Windows,
click on the link for the Latest Python 3 Release - Python 3.x.x. (As of this
writing, the latest is Python 3.6.5.)
3. Scroll to the bottom and select either Windows x86-64 executable
installer for 64-bit or Windows x86 executable installer for 32-bit.
Step 2: Run the Installer
Once we have chosen and downloaded an installer, simply run it by double-clicking
on the downloaded file. A dialog should appear that looks something like this:
fig no: 1.4.1
Then just click Install Now. That should be all there is to it. A few minutes later we
will have a working Python 3 installation on your system.
4
Basic data types
Integers
In Python 3, there is effectively no limit to how long an integer value can be. Of
course, it is constrained by the amount of memory your system has, as are all things,
but beyond that an integer can be as long as you need it to be:
>>>
>>> print(123123123123123123123123123123123123123123123123 + 1)
123123123123123123123123123123123123123123123124
Python interprets a sequence of decimal digits without any prefix to be a decimal
number:
>>>
>>> print(10)
10
The following strings can be prepended to an integer value to indicate a base other
than 10:
Prefix Interpretation Base
0b (zero + lowercase letter 'b') Binary 2
0B (zero + uppercase letter 'B')
0o (zero + lowercase letter 'o') Octal 8
0O (zero + uppercase letter 'O')
0x (zero + lowercase letter 'x') Hexadecimal 16
0X (zero + uppercase letter 'X')
For example:
>>>
>>> print(0o10)
8
>>> print(0x10)
16
>>> print(0b10)
2
5
Floating-Point Numbers
The float type in Python designates a floating-point number. Float values are specified
with a decimal point. Optionally, the character e or E followed by a positive or
negative integer may be appended to specify scientific notation:
>>>
>>> 4.2
4.2
>>> type(4.2)
<class 'float'>
>>> 4.
4.0
>>> .2
0.2
>>> .4e7
4000000.0
>>> type(.4e7)
<class 'float'>
>>> 4.2e-4
0.00042
Complex Numbers
Complex numbers are specified as <real part>+<imaginary part>j. For example:
>>>
>>> 2+3j
(2+3j)
>>> type(2+3j)
<class 'complex'>
Strings
Strings are sequences of character data. The string type in Python is called str.
6
String literals may be delimited using either single or double quotes. All the
characters between the opening delimiter and matching closing delimiter are part of
the string:
>>> print("I am a string.")
I am a string.
>>> type("I am a string.")
<class 'str'>
>>> print('I am too.')
I am too.
>>> type('I am too.')
<class 'str'>
A string in Python can contain as many characters as you wish. The only limit is your
machine’s memory resources. A string can also be empty:
>>>
>>> ''
''
Boolean Type, Boolean Context, and “Truthiness”
Python 3 provides a Boolean data type. Objects of Boolean type may have one of two
values, True or False:
>>>
>>> type(True)
<class 'bool'>
>>> type(False)
<class 'bool'>
As you will see in upcoming tutorials, expressions in Python are often evaluated in
Boolean context, meaning they are interpreted to represent truth or falsehood. A value
that is true in Boolean context is sometimes said to be “truthy,” and one that is false in
Boolean context is said to be “falsy.” (You may also see “falsy” spelled “falsey.”)
The “truthiness” of an object of Boolean type is self-evident: Boolean objects that are
equal to True are truthy (true), and those equal to False are falsy (false). But non-
7
Python operators
Arithmetic Operators
Arithmetic Operators perform various arithmetic calculations like addition,
subtraction, multiplication, division, %modulus, exponent, etc. There are various
methods for arithmetic calculation in Python like you can use the eval function,
declare variable & calculate, or call functions.
Example: For arithmetic operators we will take simple example of addition where we
will add two-digit 4+5=9
x= 4
y= 5
print(x + y)
Similarly, you can use other arithmetic operators like for multiplication (*), division
(/), subtractions (-), etc.
Comparison Operators
These operators compare the values on either side of the operand and determine the
relation between them. It is also referred as relational operators. Various comparison
operators are (==, !=, <>, >,<=, etc.)
Example: For comparison operators we will compare the value of x to the value of y
and print the result in true or false. Here in example, our value of x = 4 which is
smaller than y = 5, so when we print the value as x>y, it actually compares the value
of x to y and since it is not correct, it returns false.
x=4
y=5
print(('x > y is',x>y))
Likewise, you can try other comparison operators (x < y, x==y, x!=y, etc.)
Assignment Operators
Python assignment operators are used for assigning the value of the right operand to
the left operand. Various assignment operators used in Python are (+=, - = , *=, /= ,
etc.)
Example: Python assignment operators is simply to assign the value, for example
num1 = 4
8
print(("Line 1 - Value of num1 : ", num1))
print(("Line 2 - Value of num2 : ", num2))
Logical Operators
Logical operators in Python are used for conditional statements are true or false.
Logical operators in Python are AND, OR and NOT. For logical operators following
condition are applied.
For AND operator – It returns TRUE if both the operands (right side and left
side) are true
For OR operator- It returns TRUE if either of the operand (right side or left
side) is true
For NOT operator- returns TRUE if operand is false
Example: Here in example we get true or false based on the value of a and b
a = True
b = False
print(('a and b is', a and b))
print(('a or b is', a or b))
print(('not a is', not a))
Membership Operators
These operators test for membership in a sequence such as lists, strings or tuples.
There are two membership operators that are used in Python. (in, not in). It gives the
result based on the variable present in specified sequence or string
Example: For example here we check whether the value of x=4 and value of y=8 is
available in list or not, by using in and not in operators.
x=4
y=8
list = [1, 2, 3, 4, 5 ];
if ( x in list ):
print("Line 1 - x is available in the given list")
else:
print("Line 1 - x is not available in the given list")
9
if (y not in list):
print("Line 2 - y is not available in the given list")
else:
print("Line 2 - y is available in the given list")
Declare the value for x and y
Declare the value of list
Use the "in" operator in code with if statement to check the value of x existing
in the list and print the result accordingly
Use the "not in" operator in code with if statement to check the value of y exist
in the list and print the result accordingly
Run the code- When the code run it gives the desired output
Identity Operators
To compare the memory location of two objects, Identity Operators are used. The two
identify operators used in Python are (is, is not).
Operator is: It returns true if two variables point the same object and false
otherwise
Operators (Decreasing order of precedence) Meaning
** Exponent
*, /, //, % Multiplication, Division, Floor division, Modulus
+, - Addition, Subtraction
<= < > >= Comparison operators
= %= /= //= -= += *= **= Assignment Operators
is not Identity operators
10
in not in Membership operators
not or and Logical operators
Operator is not: It returns false if two variables point the same object and true
otherwise
Following operands are in decreasing order of precedence.
Operators in the same box evaluate left to right
Example:
x = 20
y = 20
if (x is y ):
print ("x & y SAME identity")
y=30
if (x is not y):
print ("x & y have DIFFERENT identity")
Declare the value for variable x and y
Use the operator "is" in code to check if value of x is same as y
Next we use the operator "is not" in code if value of x is not same as y
Run the code- The output of the result is as expected
11
Summary:
Operators in a programming language are used to perform various operations on
values and variables. In Python, you can use operators like
There are various methods for arithmetic calculation in Python as you can use
the eval function, declare variable & calculate, or call functions
Comparison operators often referred as relational operators are used to
compare the values on either side of them and determine the relation between
them
Python assignment operators are simply to assign the value to variable
Python also allows you to use a compound assignment operator, in a
complicated arithmetic calculation, where you can assign the result of one
operand to the other
For AND operator – It returns TRUE if both the operands (right side and left
side) are true
For OR operator- It returns TRUE if either of the operand (right side or left
side) is true
For NOT operator- returns TRUE if operand is false
There are two membership operators that are used in Python. (in, not in).
It gives the result based on the variable present in specified sequence or string
The two identify operators used in Python are (is, is not)
It returns true if two variables point the same object and false otherwise
Precedence operator can be useful when you have to set priority for which
calculation need to be done first in a complex calculation.
12
Lists in python
The most basic data structure in Python is the sequence. Each element of a sequence
is assigned a number - its position or index. The first index is zero, the second index
is one, and so forth.
Python has six built-in types of sequences, but the most common ones are lists and
tuples, which we would see in this tutorial.
There are certain things you can do with all the sequence types. These operations
include indexing, slicing, adding, multiplying, and checking for membership. In
addition, Python has built-in functions for finding the length of a sequence and for
finding its largest and smallest elements.
Python Lists
The list is the most versatile data type available in Python, which can be written as a
list of comma-separated values (items) between square brackets. Important thing
about a list is that the items in a list need not be of the same type.
Creating a list is as simple as putting different comma-separated values between
square brackets. For example −
list1 = ['physics', 'chemistry', 1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
list3 = ["a", "b", "c", "d"];
Similar to string indices, list indices start at 0, and lists can be sliced, concatenated
and so on.
Accessing Values in Lists
To access values in lists, use the square brackets for slicing along with the index or
indices to obtain value available at that index. For example −
#!/usr/bin/python3
list1 = ['physics', 'chemistry', 1997, 2000]
list2 = [1, 2, 3, 4, 5, 6, 7 ]
print ("list1[0]: ", list1[0])
print ("list2[1:5]: ", list2[1:5])
When the above code is executed, it produces the following result −
list1[0]: physics
list2[1:5]: [2, 3, 4, 5]
13
Loops in python
Decision making is required when we want to execute a code only if a certain
condition is satisfied.
The if…elif…else statement is used in Python for decision making.
Python if Statement Syntax
if test expression:
statement(s)
Here, the program evaluates the test expression and will execute statement(s) only if
the text expression is True.
If the text expression is False, the statement(s) is not executed.
In Python, the body of the if statement is indicated by the indentation. Body starts
with an indentation and the first unindented line marks the end.
Python interprets non-zero values as True. None and 0 are interpreted as False.
Python if Statement Flowchart
# If the number is positive, we print an appropriate message
num = 3
if num > 0:
print (num, "is a positive number.")
print ("This is always printed.")
num = -1
14
if num > 0:
print (num, "is a positive number.")
print ("This is also always printed.")
When you run the program, the output will be:
3 is a positive number
This is always printed
This is also always printed.
In the above example, num > 0 is the test expression.
The body of if is executed only if this evaluates to True.
When variable num is equal to 3, test expression is true and body inside body of if is
executed.
If variable num is equal to -1, test expression is false and body inside body of if is
skipped.
The print() statement falls outside of the if block (unindented). Hence, it is executed
regardless of the test expression.
Python if...else Statement
Syntax of if...else
if test expression:
Body of if
else:
Body of else
The if..else statement evaluates test expression and will execute body of if only when test
condition is True.
If the condition is False, body of else is executed. Indentation is used to separate the blocks.
Python if..else Flowchart
15
# Program checks if the number is positive or negative
# And displays an appropriate message
num = 3
# Try these two variations as well.
# num = -5
# num = 0
if num >= 0:
print("Positive or Zero")
else:
print("Negative number")
In the above example, when num is equal to 3, the test expression is true and body of if is
executed and body of else is skipped.
If num is equal to -5, the test expression is false and body of else is executed and body of if is
skipped.
If num is equal to 0, the test expression is true and body of if is executed and body of else is
skipped.
Python if...elif...else Statement
Syntax of if...elif...else
if test expression:
16
Body of if
elif test expression:
Body of elif
else:
Body of else
The elif is short for else if. It allows us to check for multiple expressions.
If the condition for if is False, it checks the condition of the next elif block and so on.
If all the conditions are False, body of else is executed.
Only one block among the several if...elif...else blocks is executed according to the condition.
The if block can have only one else block. But it can have multiple elif blocks.
Flowchart of if...elif...else
num = 3.4
# Try these two variations as well:
# num = 0
# num = -4.5
if num > 0:
17
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
When variable num is positive, Positive number is printed.
If num is equal to 0, Zero is printed.
If num is negative, Negative number is printed
Python Nested if statements
We can have a if...elif...else statement inside another if...elif...else statement. This is called
nesting in computer programming.
Any number of these statements can be nested inside one another. Indentation is the
only way to figure out the level of nesting. This can get confusing, so must be avoided
if we can.
Python Nested if Example
# In this program, we input a number
# check if the number is positive or
# negative or zero and display
# an appropriate message
# This time we use nested if
num = float(input("Enter a number: "))
if num >= 0:
if num == 0:
print("Zero")
else:
print("Positive number")
else:
print("Negative number")
18
Advantages or Benefits of Python
The Python language has diversified application in the software development
companies such as in gaming, web frameworks and applications, language
development, prototyping, graphic design applications, etc. This provides the language
a higher plethora over other programming languages used in the industry. Some of its
advantages are-
Extensive Support Libraries
It provides large standard libraries that include the areas like string operations,
Internet, web service tools, operating system interfaces and protocols. Most of the
highly used programming tasks are already scripted into it that limits the length of
the codes to be written in Python.
Integration Feature
Python integrates the Enterprise Application Integration that makes it easy to develop
Web services by invoking COM or COBRA components. It has powerful control
capabilities as it calls directly through C, C++ or Java via Jython. Python also
processes XML and other markup languages as it can run on all modern operating
systems through same byte code.
Improved Programmer’s Productivity
The language has extensive support libraries and clean object-oriented designs that
increase two to ten fold of programmer’s productivity while using the languages like
Java, VB, Perl, C, C++ and C#.
Productivity
With its strong process integration features, unit testing framework and enhanced
control capabilities contribute towards the increased speed for most applications and
productivity of applications. It is a great option for building scalable multi-protocol
network applications.
19
Limitations or Disadvantages of Python
Python has varied advantageous features, and programmers prefer this language to
other programming languages because it is easy to learn and code too. However, this
language has still not made its place in some computing arenas that includes Enterprise
Development Shops. Therefore, this language may not solve some of the enterprise
solutions, and limitations include-
Difficulty in Using Other Languages
The Python lovers become so accustomed to its features and its extensive libraries, so
they face problem in learning or working on other programming languages. Python
experts may see the declaring of cast “values” or variable “types”, syntactic
requirements of adding curly braces or semi colons as an onerous task.
Weak in Mobile Computing
Python has made its presence on many desktop and server platforms, but it is seen as a
weak language for mobile computing. This is the reason very few mobile applications
are built in it like Carbonnelle.
Gets Slow in Speed
Python executes with the help of an interpreter instead of the compiler, which causes it
to slow down because compilation and execution help it to work normally. On the
other hand, it can be seen that it is fast for many web applications too.
Run-time Errors
The Python language is dynamically typed so it has many design restrictions that are
reported by some Python developers. It is even seen that it requires more testing time,
and the errors show up when the applications are finally run.
Underdeveloped Database Access Layers
As compared to the popular technologies like JDBC and ODBC, the Python’s database
access layer is found to be bit underdeveloped and primitive. However, it cannot be
applied in the enterprises that need smooth interaction of complex legacy data.
20
Conclusion
Python is a robust programming language and provides an easy usage of the code
lines, maintenance can be handled in a great way, and debugging can be done easily
too. It has gained importance across the globe as computer giant Google has made it
one of its official programming languages.
21
Reference
1. Core python programing by Dr. R Nageshwara Rao, dreamtech publications
(Second Edition)
2. Python Programming: A Modular approach by Sheetal Taneja and Naveen
Kumar, Pearson publicatons (Second Edition)
3. Python Made Simple by Rydhm Beri, BPB Publications (First Edition)
22