Ravi

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 27

PYTHON

By- Ravi Negi


Roll no-43
Section-’H’
Branch-’CSE’
Site-www.udemy.com
What is Python…?
• Python is a general purpose programming language that is
often applied in scripting roles.
• So, Python is programming language as well as
scripting language.
• Python is also called as Interpreted language

2
History

• Invented in the Netherlands, early 90s by Guido


van Rossum
• Python was conceived in the late 1980s and
its implementation was started in December 1989
• Open sourced from the beginning

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!”

>>> “Goodbye, cruel world.”

>>> Aggies

>>> “Aggies”
>>> “Rice fight, never
die!”
>>> “3 + 2”

11
Strings

String operators:
concatenation: +
multiplication: *

>>> print “Hello”+” “+”World”


Hello World

>>> print “Hello “*2


Hello Hello

12
VARIABLES IN PYTHON

13
Variable

Create and Assigning a new Variable:


>>>headmaster=“Dumbledore”

>>>print headmaster ‘Dumbledore’

Dumbledore

14
DATA TYPES IN PYTHON
Data Type:
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.

Bytes and byte arrays, e.g. a JPEG image file.

Lists are ordered sequences of values.

Tuples are ordered, immutable sequences of values.

Sets are unordered bags of values.

16
Example:

String “Whoop!”
Integer 42
Float 3.14159
List [“John”, “Paul”,
“George”, “Ringo”]
Python can tell us about types using the type()
function:

>>> print type(“Whoop!”)


<type ‘str’>

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 −

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.

23
LOOPS & CONDITIONAL
STATEMENTS

24
Loop Type Description

while loop Repeats a statement or group of statements


while a given condition is TRUE. It tests the
condition before executing the loop body.

for loop Executes a sequence of statements multiple


times and abbreviates 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.

39
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).

26
42

You might also like