Khushi Bisht
Khushi Bisht
On
INTRODUCTION
TO
PYTHON FOR BEGINNERS
UNDER
THE GUIDANCE OF
Dr. MUKESH JOSHI
Signature Signature
STUDENT’S DECLARATION
Anurag pathak
22042921
Table Of Contents
CHAPTER 1. Introduction
1.1 Python
1.4 History of python
2.1 Variables
2.2 String
CHAPTER 6. Conclusion
INTRODUCTION TO PYTHON
Python can serve as a scripting language for web application. Libraries like NumPy ,SciPy
and Matplotlib allow the effective use of Python in scientific computing . With
specialized libraries such as Biopython and ASTROPY providing domain-specific
functionality.
History ofofPython
History Python
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 (itself inspired by SETL) capable of exception handling and interfacing with
the Amoeba operating system. Van Rossum is Python's principal author, and his
continuing central role in deciding the direction of Python is reflected in the title given to
him by the Python community, benevolent dictator for life (BDFL).
Guido Van Rossum was a fan of ‘Monty Python Flying Circus’, this is famous TV show in
Netherlands so the name Python is derived after Monty Python.
Data Type
Data types determine whether an object can do something, or whether it just would not
make sense. Other programming languages often determine whether an operation
makes sense for an object by making sure the object can never be stored somewhere
where the operation will be performed on the object (this type system is called static
typing). Python does not do that. Instead it stores the type of an object with the object,
and checks when the operation is performed whether that operation makes sense for
that object (this is called dynamic typing).Python has many native data types.
Here are the important ones:
Numbers can be integers (1 and 2), floats (1.1 and 1.2), fractions (1/2 and 2/3), or even
complex numbers.
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 a
collection of letters, the term makes sense. All the letters, numbers, and symbols in this
book could be a string. For that matter, your name could be a string, and so could your
address.
In Python, we create a string by putting quotes around text. For example, we could take
our otherwise useless
For example −
tup1 = ('physics', 'chemistry', 1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";
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]
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]
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
Loops
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 −
Python programming language provides following types of loops to handle
looping requirements:
• while loop
• for loop
• nested loop
Conditional Statements:
• if statement
• if….else statement
• nested if else statement
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.
Scope of Python
•Science
• Bioinformatics
•System Administration
•Unix
•Web logic
•Web sphere
•Web Application Development
•CGI
•Testing scripts
•System programming
•Graphical User Interface Programming
•Internet Scripting
•Component Integration
•Database Programming
•Gaming, Images, XML , Robot and more
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.
•The YouTube video sharing service is largely written in Python.