Ravi
Ravi
Ravi
2
History
3
Scope of Python
• Science
- Bioinformatics
• System Administration
-Unix
-Web logic
-Web sphere
• Web Application Development
-CGI
-Jython – Servlets
• Testing scripts
4
What can I do with Python…?
• System programming
• Graphical User Interface Programming
• Internet Scripting
• Component Integration
• Database Programming
• Gaming, Images, XML , Robot and more
5
Running Python
Once you're inside the Python interpreter, type in commands at will.
• Examples:
>>> print 'Hello world'
Hello world
6
MATH(OPERATOR) IN PYTHON
Math
Operators
add: +
subtract: -
divide: /
multiply:
*
8
Math
>>> print 3 + 12
15
>>> print 12 – 3
9
>>> print 9 + 5 – 15 + 12
11
>>> print 3 * 12 36
>>> print 12 / 3 4
>>> print 11 / 3 3
>>> print 12.0 / 3.0 4.0
>>> print 11.0 / 3.0 3.66
9
STRINGS IN PYTHON
10
Strings
>>> “It’s a beautiful day!”
>>> Aggies
>>> “Aggies”
>>> “Rice fight, never
die!”
>>> “3 + 2”
11
Strings
String operators:
concatenation: +
multiplication: *
12
VARIABLES IN PYTHON
13
Variable
Dumbledore
14
DATA TYPES IN PYTHON
Data Type:
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.
16
Example:
String “Whoop!”
Integer 42
Float 3.14159
List [“John”, “Paul”,
“George”, “Ringo”]
Python can tell us about types using the type()
function:
17
LIST: DATA TYPE
18
List:
The list is a 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 items in a list need not be of the same type.
Example:
list1 = ['physics', 'chemistry', 1997, 2000];
list2 = [1, 2, 3, 4, 5 ];
19
Lists
>>> Beatles = [“John”, “Paul”, “George”,
“Ringo”]
>>> Beatles[0]
‘John‘
[“John”, “Paul”, “George”, “Ringo”]
0 2 3
1
20
TUPLE: DATA TYPE
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, whereas lists use square brackets.
Example:
tup2 = (1, 2, 3, 4, 5 );
tup3 = ("a", "b", "c", "d“);
Accessing Values:
print "tup2[1:5]: “
Output:
tup2[1:5]: [2, 3, 4,
5] 22
Built-in Tuple Functions
Python includes the following tuple functions −
23
LOOPS & CONDITIONAL
STATEMENTS
24
Loop Type Description
nested loops You can use one or more loop inside any
another while, for or do..while loop.
39
Statement Description
26
42