Python Report Card
Python Report Card
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
3
CHAPTER 6.
6.1 Advantages of Python
6.2 Disadvantages of Python
6.3 Conclusion
4
INTRODUCTION
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
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
>>>
>>> print(10)
10
The following strings can be prepended to an integer value to indicate a base other
than 10:
>>>
>>> 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:
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:
>>>
>>> ''
''
>>>
>>> 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")
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
** Exponent
+, - Addition, Subtraction
10
in not in Membership operators
Operator is not: It returns false if two variables point the same object and true
otherwise
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")
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.
13
Loops in python
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.
14
if num > 0:
print (num, "is a positive number.")
print ("This is also always printed.")
3 is a positive number
This is always printed
This is also always printed.
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.
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")
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.
18
Advantages or Benefits of Python
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.
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-
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.
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.
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.
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