Acknowledgment
I wish to express my profound gratitude to the almighty with whose grace and
blessing, I have been able to complete another chapter of my life.
I would like to extend my appreciation to my industrial supervisor, Mr. Tarun Jain for
his advices and patiently guiding me through while I working here as a trainee .I very
much appreciate for their entire kindness helping and teaching me when I am working
there. I am very lucky to have such a helpful colleagues and I never felt left out in any
situation.
I wish learnt a lot of valuable things while working here. I realize that learning is never
the same when it comes to practice. I wish to extend my sincere gratitude to Mr.
Aashish Sir and faculty of CSE department for their guidance, encouragement and
valuable suggestion which proved extremely useful and helpful in completion of this
industrial training.
I find no words to acknowledgment the sacrifice, help and inspiration rendered by my
parents to take up this study.
With thanks to all,
Madhur Jain
220130800032
5th Semester
Computer Engineering
Table of Contents
i. Introduction ………………….....................................................1
ii. Features ………………………………………………………………... 1
iii. History …………………………………………………………………..2
iv. Python Version ……………………………………………………..…2
v. Running the Python IDLE……………………………………………3
vi. Python Code Execution ……………………………………………..3
vii. Data Type………………………………………………………………..4
viii. Variable ………………………………………………………………....5
ix. String ………………………………………………………………….5-6
x. Function………………………………………………………………....6
xi. Tuple …………………………………………………………………...7-8
xii. List……………………………………………………………………..8-10
xiii. Loops………………………………………………………………....11-12
xiv. Conditional Statement……………………………………….....13-14
xv. Scope of Python ………………………………………………….…..14
xvi. What can be do with Python ?…………………………………….14
xvii. Who uses Python today?…………………………………………....15
xviii. Why do people use Python ?……………………………………….15
Python
Python is a widely used high-level, general-purpose, interpreted, dynamic programming
language. Python programming language was developed by Guido Van Rossum in 1991.
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 support multiple programming pattern, including object oriented, imperative and
functional or procedural programming styles. Python makes the development and
debugging fast because there is no compilation step included in python development
and edit-test-debug cycle is very fast.
Python Features
1. Easy to Learn and Use: Python is easy to learn and use. It is developer-friendly and high
level programming language.
2. Expressive Language: Python language is more expressive means that it is more
understandable and readable.
3. Interpreted Language: Python is an interpreted language i.e. interpreter executes the code
line by line at a time. This make debugging easy and thus suitable for beginners.
4. Cross-platform Language: Python can run equally on different platforms such as
Windows, Linux, Unix and Macintosh etc. So, we can say that Python is a portable language.
5. Free and Open Source: Python language is freely available at official web address. The
source-code is also available. Therefore it is open source.
6. GUI Programming Support: Graphical user interfaces can be developed using Python.
7. Integrated: It can be easily integrated with languages like C, C++, JAVA etc.
8. Large Standard Library: Python has a large and broad library and provides rich set of
module and functions for rapid application development.
9. Object-Oriented Language: Python supports object oriented language and concepts of
classes and objects come into existence.
1
History
Python was conceived in the late 1980s, and its implementation was started in December 1989
by Guido van Rossum at CWI in the Netherlands as a successor to the ABC language capable of
exception handling and interfacing with the Amoeba operating system.
Python Version List
Python programming language is being updated regularly with new features and supports.
There are lots of updations in python versions, started from 1994 to current release.
2
Running The Python IDLE
1. Install Python (if not installed):
If Python is not installed on your system, follow these steps:
• Go to the official Python website.
• Download the latest version of Python for Windows.
• During installation, make sure to check the box that says “Add Python to PATH” at the
beginning of the installation wizard.
• After installation completes, Python and IDLE should be ready to use.
2. Open Python IDLE:
• Once Python is installed, you can open IDLE by following these steps:
• Press the Windows key on your keyboard to open the Start Menu.
• Type IDLE into the search bar. You should see something like “IDLE (Python 3.x 64-bit)”
(where x represents the version number you installed).
• Click on it to launch the Python IDLE.
3. Using Python IDLE:
• Once IDLE is open, you’ll see the Python Shell where you can directly type and run
Python code interactively.
• To run Python code directly in the shell, just type it and press Enter.
• To create a Python script, go to File > New File, write your code, and then save the file
with a .py extension.
• To run a saved Python script, press F5 or go to Run > Run Module.
Python Code Execution
Python’s traditional runtime execution model: source code you type is translated to byte code, which is
then run by the Python Virtual Machine. Your code is automatically compiled, but then it is interpreted.
Source code extension is .py
Byte code extension is .pyc (compiled python code)
3
Data Type
In Python, a data type refers to the classification of data based on the kind of value it holds.
Data types determine the operations that can be performed on the data and the kind of
values the data can store. Python is a dynamically typed language, meaning you do not
need to explicitly declare a variable’s type when you create it, and the type can change
during execution.
Each variable or value in Python has a specific data type that defines the nature of the data.
The data type essentially tells Python how to handle and store the data in memory.
Python has many native data types. Here are the important ones:
Booleans are either True or False.
Numbers can be integers (1 and 2), floats (1.1 and 1.2), fractions (1/2 and 2/3), or even complex
numbers.
Strings are sequences of Unicode characters, e.g. an HTML document.
Range represents a sequence of numbers, typically used in loops. It generates numbers in a specific range
Lists are ordered sequences of values.
Tuples are ordered, immutable sequences of values.
Sets are unordered bags of values.
None Represents the absence of a value or a null value (e.g., None)
4
Variable
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 type 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.
Ex: counter = 100 # An integer
assignment miles = 1000.0 # A floating
point name = "John" # A string
String
In programming terms, we usually call text a string. When you think of a string as acollection
of letters, the term makes sense.
All the letters, numbers, and symbols in this book could be string. For
that matter, your name could be a string, and so couldyour address.
Creating Strings
In Python, we create a string by putting quotes around text. For example, we could take our otherwise
useless
• "hello"+"world" "helloworld" # concatenation
5
• "hello"*3 "hellohellohello" # repetition
• "hello"[0] "h" # indexing
• "hello"[-1] "o" # (from end)
• "hello"[1:4] "ell" # slicing
• len("hello") 5 # size
• "hello" < "jello" 1 # comparison
• "e" in "hello" 1 # search
Function
Function blocks begin with the keyword def followed by the function name and parentheses (( )).
Any input parameters or arguments should be placed within these parentheses. You can also define
parameters inside these parentheses.
The first statement of a function can be an optional statement – the documentation string of the function.
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.
Syntax:
def function_name(parameters):
function-suite
return[expression]
Example:
def printme(str):
print(“this print a passed string into this function”)
Return
1. # Function definition is here def printme( str ):
“This prints a passed string into this function” print str return;
# Now you can call printme function printme(“I’m first call to user defined function!”) printme(“Again second
call to the same function”)
6
Tuples
A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences
between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses.
Accessing Values in Tuples:
To access values in tuple, use the square brackets for slicing along with the index or
indices to obtain value available at that index. For example − tup1 = ('physics', 'chemistry',
1997, 2000); tup2 = (1, 2, 3, 4, 5, 6, 7 ); print "tup1[0]: ", tup1[0] print "tup2[1:5]: ", tup2[1:5]
When the above code is executed, it produces the following result − tup1[0]:
physics tup2[1:5]: [2, 3, 4, 5]
Basic Tuples Operations
Tuples respond to the + and * operators much like strings; they mean concatenation and
repetition here too, except that the result is a new tuple, not a string. In fact, tuples respond
to all of the general sequence operations we used on strings in the prior chapter
−
Python Expression Results Description
len((1, 2, 3)) 3 Length
(1, 2, 3) + (4, 5, 6) (1, 2, 3, 4, 5, 6) Concatenation
('Hi!',) * 4 ('Hi!', 'Hi!', 'Hi!', 'Hi!') Repetition
3 in (1, 2, 3) True Membership
for x in (1, 2, 3): print x, 123 Iteration
7
Built-in Tuple Functions
Python includes the following tuple functions −
SN Function with Description
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 min value.
5 tuple(seq) Converts a list into tuple.
List
The list is a most versatile datatype 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 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 − 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]
8
Output: list1[0]: physics
list2[1:5]: [2, 3, 4, 5]
Update: list = ['physics', 'chemistry', 1997, 2000]; print
"Value available at index 2 : " print list[2] list[2] = 2001; print
"New value available at index 2 : " print list[2]
Output: Value available at index 2 :
1997 New value available at index 2 :
2001
Delete: list1 = ['physics', 'chemistry', 1997, 2000]; print
list1 del list1[2]; print "After deleting value at index 2 : " print
list1
['physics', 'chemistry', 1997, 2000] Output:
After deleting value at index 2 :['physics',
'chemistry', 2000]
Basic List Operation
Python Expression Results Description
len([1, 2, 3]) 3 Length
[1, 2, 3] + [4, 5, 6] [1, 2, 3, 4, 5, 6] Concatenation
['Hi!'] * 4 ['Hi!', 'Hi!', 'Hi!', 'Hi!'] Repetition
3 in [1, 2, 3] True Membership
for x in [1, 2, 3]: print x, 123 Iteration
9
Built-in List Functions:
S Function with Description
N
1 cmp(list1, list2) Compares elements of both lists.
2 len(list) Gives the total length of the list.
3 max(list) Returns item from the list with max value.
4 min(list) Returns item from the list with min value.
5 list(seq) Converts a tuple into list.
10
Loop definition
Programming languages provide various control structures that allow for more complicated
execution paths.
A loop statement allows us to execute a statement or group of statements multiple times. The
following diagram illustrates a loop statement −
> Greater than - True if left operand is greater than the right x> y
< Less than-True if left operand is less than the right x<y
== Equal to - True if both operands are equal x==y
!= Not equal to – True if operands are not equal x!= y
Greater than or equal to - True if left operand is greater than or equal to the
>= x>= y
right
x<=y
<= Less than or equal to – True if left operand is less than or equal to the right
11
Python programming language provides following types of loops to handle looping
requirements.
Loop Type Description
while loop Repeats a statement or group of statements while a given
condition is TRUE. It tests the condition before executing theloop
body.
for loop Executes a sequence of statements multiple times andabbreviates
the code that manages the loop variable.
nested loops You can use one or more loop inside any another while, for or
do..while loop.
Loop Example:
For Loop:
>>> for mynum in [1, 2, 3, 4, 5]:
print (“Hello”, mynum )
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
While Loop:
>>> count = 0
>>>while(count< 4):
print( “The count is:” count = count + 1)
The count is: 0
The count is: 1
The count is: 2
The count is: 3
12
Conditional Statements:
Decision making is anticipation of conditions occurring while execution of the program and specifying
actions taken according to the conditions.
Decision structures evaluate multiple expressions which produce TRUE or FALSE as
outcome. You need to determine which action to take and which statements to execute if
outcome is TRUE or FALSE otherwise.
Python programming language provides following types of decision making statements. Click the
following links to check their detail.
Statement Description
if statements An if statement consists of a boolean expression
followed by one or more statements.
if...else statements An if statement can be followed by an optional else
statement, which executes when the boolean expression
is FALSE.
nested if statements You can use one if or else if statement
inside another if or else if statement(s).
13
Example:
If Statement:
a=33
b=200
if b>a:
print(“b”)
If...Else Statement:
a=200
b=33
if b>a:
print(“b is greater than a”)
else:
print(“a is greater than b”)
SCOPE OF PYTHON
1 - Science
- Bioinformatics
2 - System Administration
- Unix
- Web logic
- Web sphere
3 - Web Application Development
What Can We do With Python?
1 System programming
2 Graphical User Interface
3 Internet Scripting
4 Component Integration
14
WHO USES PYTHON TODAY?
• Python is being applied in real revenue-generating products by real companies.
• Google makes extensive use of Python in its web search system, and employs Python’s
creator.
• Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for hardware testing.
• ESRI uses Python as an end-user customization tool for its popular GIS mapping products.
WHY DO PEOPLE USE PYTHON?
• The YouTube video sharing service is largely written in Python.
• Python is object-oriented o Structure supports such concepts as
polymorphism, operation overloading, and multiple inheritance.
• Indentation o Indentation is one of the greatest future in Python.
• It's free (open source) o Downloading and installing Python is free and
easy o Source code is easily accessible
• It's powerful o Dynamic typing o Built-in types and tools o Library
utilities
o Third party utilities (e.g. Numeric, NumPy, SciPy) o
Automatic memory management
• It's portable o Python runs virtually every major platform used today
o As long as you have a compatible Python interpreter installed,
Python programs will run in exactly the same manner, irrespective of
platform.
15