SlideShare a Scribd company logo
1 of 41
Python Programming
Python is a high-level, interpreted, interactive and object-oriented
scripting language.
●

●

●

Python is Interpreted: This means that it is processed at runtime
by the interpreter and you do not need to compile your program
before executing it.
Python is Interactive: This means that you can actually sit at a
Python prompt and interact with the interpreter directly to write
your programs
Python is Object-Oriented: This means that Python supports
Object-Oriented style
History of Python

Python was developed by Guido van Rossum in the late
eighties and early nineties at the National Research Institute for
Mathematics and Computer Science in the Netherlands.
C++...etc

Python is derived from many other languages, including C,
Python Features
➢ Easy-to-learn: Python has relatively few keywords, simple structure,

and a clearly defined syntax. This allows the student to pick up the
language in a relatively short period of time.

➢ Easy-to-read: Python code is much more clearly defined and visible

to the eyes.

➢ Easy-to-maintain: Python's success is that its source code is fairly

easy-to-maintain.

➢ Portable: Python can run on a wide variety of hardware platforms and

has the same interface on all platforms.

➢ Extendable: You can add low-level modules to the Python interpreter.
Python Basic Syntax
The Python language has many similarities to C and Java. However, there are
some definite differences between the languages like in syntax also.

Python Identifiers:
A Python identifier is a name used to identify a variable, function, class, module
or other object. An identifier starts with a letter A to Z or a to z or an underscore
(_) followed by zero or more letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $ and % within
identifiers. Python is a case sensitive programming language. Thus, Manpower
and manpower are two different identifiers in Python.
Reserved Words:
The following list shows the reserved words in Python.
These reserved words may not be used as constant or variable or any
other identifier names. All the Python keywords contain lowercase
letters only.
and
assert
break
class
continue
def
del
elif
else
except

exec
finally
for
from
global
if
import
in
is
lambda

not
or
pass
print
raise
return
try
while
with
yield
Lines and Indentation:

In python there are no braces to indicate blocks of code for
class and function definitions or flow control. Blocks of code are
denoted by line indentation.
The number of spaces in the indentation is variable, but all
statements within the block must be indented the same amount. Both
blocks in this example are fine:
Example:
if True:
print "True"
else:
print "False"
However, the second block in this example will generate an error:
if True:
print "Answer"
print "True"
else:
print "Answer"
print "False" <----Error
Thus, in Python all the continous lines indented with similar number of spaces would form a block.
Multi-Line Statements:
Statements in Python typically end with a new line. Python does, however, allow the use of the
line continuation character () to denote that the line should continue.
Example:
total = item_one + 
item_two + 
item_three

<----New line charactor

Statements contained within the [], {} or () brackets do not need to use the line continuation character.
Example:
days = ['Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday']
Quotation in Python:

Python accepts single ('), double (") and triple (''' or """) quotes to denote string
literals, as long as the same type of quote starts and ends the string.The triple quotes can be used
to span the string across multiple lines

Example:
word = 'word'

<--------------- single

sentence = "This is a sentence."

<------------- double

paragraph = """This is a paragraph. It is
made up of multiple lines and sentences.""" <------------ triple
Python Variable Types
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.
Assigning Values to Variables:
Python variables do not have to be explicitly declared to reserve memory space.
The declaration happens automatically when you assign a value to a variable. The equal
sign (=) is used to assign values to variables.
The operand to the left of the = operator is the name of the variable and the operand
to the right of the = operator is the value stored in the variable.
Example:
counter = 100
miles = 1000.0
name = "John"

# An integer assignment
# A floating point
# A string

print counter
print miles
print name
Here, 100, 1000.0 and "John" are the values assigned to counter, miles and name variables, respectively.
While running this program, this will produce the following result:
Output:
100
1000.0
John
Multiple Assignment:
Python allows you to assign a single value to several variables simultaneously.
Example:
a=b=c=1
Here, an integer object is created with the value 1, and all three variables are assigned to
the same memory location.
You can also assign multiple objects to multiple variables. For example:
a, b, c = 1, 2, "john"

Here, two integer objects with values 1 and 2 are assigned to variables a and b, and one
string object with the value "john" is assigned to the variable c.
Python Numbers:
Number data types store numeric values. They are immutable data types which means that changing
the value of a number data type results in a newly allocated object.
Number objects are created when you assign a value to them.
For example:
var1 = 1
var2 = 10
You can delete a single object or multiple objects by using the del statement.
For example:
del var
del var_a, var_b
Python supports four different numerical types:


int



long



float



complex

int : 10 , -786
long : 51924361L , -0x19323L
float : 0.0 , -21.9
complex : 3.14j
Python Strings:
Strings in Python are identified as a contiguous set of characters in between quotation
marks. Python allows for either pairs of single or double quotes. Subsets of strings can be
taken using the slice operator ( [ ] and [ : ] ) with indexes starting at 0 in the beginning of
the string and working their way from -1 at the end.
The plus ( + ) sign is the string concatenation operator and the asterisk ( * ) is the
repetition operator.
Example:
str = 'Hello World!'
print str
print str[0]

# Prints complete string
# Prints first character of the string
print str[2:5]

# Prints characters starting from 3rd to 5th

print str[2:]

# Prints string starting from 3rd character

print str * 2

# Prints string two times

print str + "TEST" # Prints concatenated string
Output:
Hello World!
H
llo
llo World!
Hello World!Hello World!
Hello World!TEST
Python Lists:
Lists are the most versatile of Python's compound data types. A list contains items separated by
commas and enclosed within square brackets ([]).
Example:
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tinylist = [123, 'john']
print list

# Prints complete list

print list[0]

# Prints first element of the list

print list[1:3]

# Prints elements starting from 2nd till 3rd

print list[2:]

# Prints elements starting from 3rd element

print tinylist * 2 # Prints list two times
print list + tinylist # Prints concatenated lists
Python Tuples:
A tuple is another sequence data type that is similar to the list. A
tuple consists of a number of values separated by commas. Unlike lists,
however, tuples are enclosed within parentheses.
The main differences between lists and tuples are: Lists are
enclosed in brackets ( [ ] ) and their elements and size can be changed,
while tuples are enclosed in parentheses ( ( ) ) and cannot be updated.
Example:
tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
tinytuple = (123, 'john')
print tuple

# Prints complete list

print tuple[0]

# Prints first element of the list

print tuple[1:3]

# Prints elements starting from 2nd till 3rd

print tuple[2:]

# Prints elements starting from 3rd element

print tinytuple * 2 # Prints list two times
print tuple + tinytuple # Prints concatenated lists
Output:
('abcd', 786, 2.23, 'john', 70.200000000000003)
abcd
(786, 2.23)
(2.23, 'john', 70.200000000000003)
(123, 'john', 123, 'john')
('abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john')
Following is invalid with tuple, because we attempted to update a tuple, which is
not allowed. Similar case is possible with lists:
tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
tuple[2] = 1000 # Invalid syntax with tuple
list[2] = 1000

# Valid syntax with list
Python Dictionary:
Python's dictionaries are kind of hash table type. They work like associative arrays
or hashes found in Perl and consist of key-value pairs. A dictionary key are usually
numbers or strings.
Dictionaries are enclosed by curly braces ( { } ) and values can be assigned and
accessed using square braces ( [] ). For example:
dict = {}
dict['one'] = "This is one"
dict[2]

= "This is two"

tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
print dict['one']

# Prints value for 'one' key

print dict[2]

# Prints value for 2 key

print tinydict

# Prints complete dictionary

print tinydict.keys() # Prints all the keys
print tinydict.values() # Prints all the values
Output:
This is one
This is two
{'dept': 'sales', 'code': 6734, 'name': 'john'}
['dept', 'code', 'name']
['sales', 6734, 'john']
Operators
Simple answer can be given using expression 4 + 5 is equal to 9. Here, 4 and 5 are
called operands and + is called operator. Python language supports the following types
of operators.
➢ Arithmetic Operators
➢ Comparison (i.e., Relational) Operators
➢ Assignment Operators
➢ Logical Operators
➢ Bitwise Operators
➢ Membership Operators
➢ Identity Operators
Python Arithmetic Operator
a = 21
b = 10
C=0
c=a+b
print "Line 1 - Value of c is ", c
c=a-b
print "Line 2 - Value of c is ", c
c=a*b
print "Line 3 - Value of c is ", c
c=a/b
print "Line 4 - Value of c is ", c
c=a%b
print "Line 5 - Value of c is ", c
a=2
b=3
c = a**b
print "Line 6 - Value of c is ", c
a = 10
b=5
c = a//b
print "Line 7 - Value of c is ", c
Output:
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of c is 2
Line 5 - Value of c is 1
Line 6 - Value of c is 8
Line 7 - Value of c is 2
Python Comparison Operator
Python Assignment Operator
Bitwise Operator
Logical Operator
Membership Operator
Example:
a = 10
b = 20
list = [1, 2, 3, 4, 5 ];
if ( a in list ):
print "Line 1 - a is available in the given list"
else:
print "Line 1 - a is not available in the given list"
if ( b not in list ):
print "Line 2 - b is not available in the given list"
else:
print "Line 2 - b is available in the given list"
a=2
if ( a in list ):
print "Line 3 - a is available in the given list"
else:
print "Line 3 - a is not available in the given list"
Output:
Line 1 - a is not available in the given list
Line 2 - b is not available in the given list
Line 3 - a is available in the given list
Identity Operators
a = 20
b = 20
if ( a is b ):
print "Line 1 - a and b have same identity"
else:
print "Line 1 - a and b do not have same identity"
b = 30
if ( a is b ):
print "Line 3 - a and b have same identity"
else:
print "Line 3 - a and b do not have same identity"
if ( a is not b ):
print "Line 4 - a and b do not have same identity"
else:
print "Line 4 - a and b have same identity"
Output:
Line 1 - a and b have same identity
Line 3 - a and b do not have same identity
Line 4 - a and b do not have same identity
Python slide.1
Python slide.1

More Related Content

What's hot

What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaEdureka!
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda FunctionMd Soyaib
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Edureka!
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in PythonSumit Satam
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaEdureka!
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and commentsNilimesh Halder
 
Python oop - class 2 (inheritance)
Python   oop - class 2 (inheritance)Python   oop - class 2 (inheritance)
Python oop - class 2 (inheritance)Aleksander Fabijan
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaEdureka!
 

What's hot (20)

What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda Function
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
Python Loops Tutorial | Python For Loop | While Loop Python | Python Training...
 
Basic Concepts in Python
Basic Concepts in PythonBasic Concepts in Python
Basic Concepts in Python
 
What is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | EdurekaWhat is Python Lambda Function? Python Tutorial | Edureka
What is Python Lambda Function? Python Tutorial | Edureka
 
Python ppt
Python pptPython ppt
Python ppt
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
C++ string
C++ stringC++ string
C++ string
 
Lesson 03 python statement, indentation and comments
Lesson 03   python statement, indentation and commentsLesson 03   python statement, indentation and comments
Lesson 03 python statement, indentation and comments
 
Python oop - class 2 (inheritance)
Python   oop - class 2 (inheritance)Python   oop - class 2 (inheritance)
Python oop - class 2 (inheritance)
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
pointer-to-object-.pptx
pointer-to-object-.pptxpointer-to-object-.pptx
pointer-to-object-.pptx
 
Python oop class 1
Python oop   class 1Python oop   class 1
Python oop class 1
 
Types of methods in python
Types of methods in pythonTypes of methods in python
Types of methods in python
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Python programming
Python programmingPython programming
Python programming
 

Viewers also liked

πετρινα γεφυρια (4)
πετρινα γεφυρια (4)πετρινα γεφυρια (4)
πετρινα γεφυρια (4)Theod13
 
Pp65tahun2005
Pp65tahun2005Pp65tahun2005
Pp65tahun2005frans2014
 
Analisa ecotects
Analisa ecotectsAnalisa ecotects
Analisa ecotectsfrans2014
 
Tugassejaraharsitektur 131112083046-phpapp01
Tugassejaraharsitektur 131112083046-phpapp01Tugassejaraharsitektur 131112083046-phpapp01
Tugassejaraharsitektur 131112083046-phpapp01frans2014
 
Perencanaan sambungan-profil-baja
Perencanaan sambungan-profil-bajaPerencanaan sambungan-profil-baja
Perencanaan sambungan-profil-bajafrans2014
 
P.o.m project report
P.o.m project reportP.o.m project report
P.o.m project reportmounikapadiri
 
Emcdevteam com topbostoncriminallawyer_practice_theft-crimes
Emcdevteam com topbostoncriminallawyer_practice_theft-crimesEmcdevteam com topbostoncriminallawyer_practice_theft-crimes
Emcdevteam com topbostoncriminallawyer_practice_theft-crimesLaurena Campos
 
Ppipp copy-130823044640-phpapp02
Ppipp copy-130823044640-phpapp02Ppipp copy-130823044640-phpapp02
Ppipp copy-130823044640-phpapp02frans2014
 
Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...
Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...
Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...Clipping Path India
 
ნარჩენების სრულად დაშლის დროNew microsoft office power point presentation
ნარჩენების სრულად დაშლის დროNew microsoft office power point presentationნარჩენების სრულად დაშლის დროNew microsoft office power point presentation
ნარჩენების სრულად დაშლის დროNew microsoft office power point presentationNato Khuroshvili
 
[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)
[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)
[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)інна гаврилець
 
μυστράς στοιχεία αρχιτεκτονικής
μυστράς στοιχεία αρχιτεκτονικήςμυστράς στοιχεία αρχιτεκτονικής
μυστράς στοιχεία αρχιτεκτονικήςTheod13
 
Tradie Exchange Jobs Australia
Tradie Exchange Jobs AustraliaTradie Exchange Jobs Australia
Tradie Exchange Jobs AustraliaTradieExchange
 
μυστράς (2)
μυστράς (2)μυστράς (2)
μυστράς (2)Theod13
 
S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02
S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02
S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02frans2014
 

Viewers also liked (18)

πετρινα γεφυρια (4)
πετρινα γεφυρια (4)πετρινα γεφυρια (4)
πετρινα γεφυρια (4)
 
Pp65tahun2005
Pp65tahun2005Pp65tahun2005
Pp65tahun2005
 
Analisa ecotects
Analisa ecotectsAnalisa ecotects
Analisa ecotects
 
Tugassejaraharsitektur 131112083046-phpapp01
Tugassejaraharsitektur 131112083046-phpapp01Tugassejaraharsitektur 131112083046-phpapp01
Tugassejaraharsitektur 131112083046-phpapp01
 
Python session3
Python session3Python session3
Python session3
 
Html
HtmlHtml
Html
 
Perencanaan sambungan-profil-baja
Perencanaan sambungan-profil-bajaPerencanaan sambungan-profil-baja
Perencanaan sambungan-profil-baja
 
P.o.m project report
P.o.m project reportP.o.m project report
P.o.m project report
 
Emcdevteam com topbostoncriminallawyer_practice_theft-crimes
Emcdevteam com topbostoncriminallawyer_practice_theft-crimesEmcdevteam com topbostoncriminallawyer_practice_theft-crimes
Emcdevteam com topbostoncriminallawyer_practice_theft-crimes
 
Ppipp copy-130823044640-phpapp02
Ppipp copy-130823044640-phpapp02Ppipp copy-130823044640-phpapp02
Ppipp copy-130823044640-phpapp02
 
Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...
Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...
Photoshop Tutorial Clipping path service, Photoshop clipping path. photo clip...
 
ნარჩენების სრულად დაშლის დროNew microsoft office power point presentation
ნარჩენების სრულად დაშლის დროNew microsoft office power point presentationნარჩენების სრულად დაშლის დროNew microsoft office power point presentation
ნარჩენების სრულად დაშლის დროNew microsoft office power point presentation
 
[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)
[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)
[S hegda a.v.]_ekonomіka_pіdpriєmstva._zbіrnik_(book_fi.org)
 
μυστράς στοιχεία αρχιτεκτονικής
μυστράς στοιχεία αρχιτεκτονικήςμυστράς στοιχεία αρχιτεκτονικής
μυστράς στοιχεία αρχιτεκτονικής
 
δ.θ
δ.θδ.θ
δ.θ
 
Tradie Exchange Jobs Australia
Tradie Exchange Jobs AustraliaTradie Exchange Jobs Australia
Tradie Exchange Jobs Australia
 
μυστράς (2)
μυστράς (2)μυστράς (2)
μυστράς (2)
 
S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02
S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02
S1 teoper-2-konsepdasarperencanaanpembangunan-130614084228-phpapp02
 

Similar to Python slide.1

CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxfaithxdunce63732
 
1. python programming
1. python programming1. python programming
1. python programmingsreeLekha51
 
Python quick guide
Python quick guidePython quick guide
Python quick guideHasan Bisri
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
CS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdfCS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdfIda Lumintu
 
Python interview questions
Python interview questionsPython interview questions
Python interview questionsPragati Singh
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)ssuser7f90ae
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in pythonsunilchute1
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Pythonshailaja30
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on SessionDharmesh Tank
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 

Similar to Python slide.1 (20)

CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
 
1. python programming
1. python programming1. python programming
1. python programming
 
Python basics
Python basicsPython basics
Python basics
 
Python quick guide
Python quick guidePython quick guide
Python quick guide
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
unit 1.docx
unit 1.docxunit 1.docx
unit 1.docx
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
CS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdfCS-XII Python Fundamentals.pdf
CS-XII Python Fundamentals.pdf
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
Python standard data types
Python standard data typesPython standard data types
Python standard data types
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Introduction To Python
Introduction To  PythonIntroduction To  Python
Introduction To Python
 
Python programming
Python  programmingPython  programming
Python programming
 
Python PPT2
Python PPT2Python PPT2
Python PPT2
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 

More from Aswin Krishnamoorthy

More from Aswin Krishnamoorthy (6)

Http request&response
Http request&responseHttp request&response
Http request&response
 
Ppt final-technology
Ppt final-technologyPpt final-technology
Ppt final-technology
 
Windows 2012
Windows 2012Windows 2012
Windows 2012
 
Virtualization session3
Virtualization session3Virtualization session3
Virtualization session3
 
Virtualization session3 vm installation
Virtualization session3 vm installationVirtualization session3 vm installation
Virtualization session3 vm installation
 
Python session3
Python session3Python session3
Python session3
 

Recently uploaded

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 

Recently uploaded (20)

call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 

Python slide.1

  • 1.
  • 2. Python Programming Python is a high-level, interpreted, interactive and object-oriented scripting language. ● ● ● Python is Interpreted: This means that it is processed at runtime by the interpreter and you do not need to compile your program before executing it. Python is Interactive: This means that you can actually sit at a Python prompt and interact with the interpreter directly to write your programs Python is Object-Oriented: This means that Python supports Object-Oriented style
  • 3. History of Python Python was developed by Guido van Rossum in the late eighties and early nineties at the National Research Institute for Mathematics and Computer Science in the Netherlands. C++...etc Python is derived from many other languages, including C,
  • 4. Python Features ➢ Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined syntax. This allows the student to pick up the language in a relatively short period of time. ➢ Easy-to-read: Python code is much more clearly defined and visible to the eyes. ➢ Easy-to-maintain: Python's success is that its source code is fairly easy-to-maintain. ➢ Portable: Python can run on a wide variety of hardware platforms and has the same interface on all platforms. ➢ Extendable: You can add low-level modules to the Python interpreter.
  • 5. Python Basic Syntax The Python language has many similarities to C and Java. However, there are some definite differences between the languages like in syntax also. Python Identifiers: A Python identifier is a name used to identify a variable, function, class, module or other object. An identifier starts with a letter A to Z or a to z or an underscore (_) followed by zero or more letters, underscores and digits (0 to 9). Python does not allow punctuation characters such as @, $ and % within identifiers. Python is a case sensitive programming language. Thus, Manpower and manpower are two different identifiers in Python.
  • 6. Reserved Words: The following list shows the reserved words in Python. These reserved words may not be used as constant or variable or any other identifier names. All the Python keywords contain lowercase letters only.
  • 8. Lines and Indentation: In python there are no braces to indicate blocks of code for class and function definitions or flow control. Blocks of code are denoted by line indentation. The number of spaces in the indentation is variable, but all statements within the block must be indented the same amount. Both blocks in this example are fine:
  • 9. Example: if True: print "True" else: print "False" However, the second block in this example will generate an error: if True: print "Answer" print "True" else: print "Answer" print "False" <----Error Thus, in Python all the continous lines indented with similar number of spaces would form a block.
  • 10. Multi-Line Statements: Statements in Python typically end with a new line. Python does, however, allow the use of the line continuation character () to denote that the line should continue. Example: total = item_one + item_two + item_three <----New line charactor Statements contained within the [], {} or () brackets do not need to use the line continuation character. Example: days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
  • 11. Quotation in Python: Python accepts single ('), double (") and triple (''' or """) quotes to denote string literals, as long as the same type of quote starts and ends the string.The triple quotes can be used to span the string across multiple lines Example: word = 'word' <--------------- single sentence = "This is a sentence." <------------- double paragraph = """This is a paragraph. It is made up of multiple lines and sentences.""" <------------ triple
  • 12. Python Variable Types 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. Assigning Values to Variables: Python variables do not have to be explicitly declared to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable.
  • 13. Example: counter = 100 miles = 1000.0 name = "John" # An integer assignment # A floating point # A string print counter print miles print name Here, 100, 1000.0 and "John" are the values assigned to counter, miles and name variables, respectively. While running this program, this will produce the following result: Output: 100 1000.0 John
  • 14. Multiple Assignment: Python allows you to assign a single value to several variables simultaneously. Example: a=b=c=1 Here, an integer object is created with the value 1, and all three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables. For example: a, b, c = 1, 2, "john" Here, two integer objects with values 1 and 2 are assigned to variables a and b, and one string object with the value "john" is assigned to the variable c.
  • 15. Python Numbers: Number data types store numeric values. They are immutable data types which means that changing the value of a number data type results in a newly allocated object. Number objects are created when you assign a value to them. For example: var1 = 1 var2 = 10 You can delete a single object or multiple objects by using the del statement. For example: del var del var_a, var_b
  • 16. Python supports four different numerical types:  int  long  float  complex int : 10 , -786 long : 51924361L , -0x19323L float : 0.0 , -21.9 complex : 3.14j
  • 17. Python Strings: Strings in Python are identified as a contiguous set of characters in between quotation marks. Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ( [ ] and [ : ] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end. The plus ( + ) sign is the string concatenation operator and the asterisk ( * ) is the repetition operator. Example: str = 'Hello World!' print str print str[0] # Prints complete string # Prints first character of the string
  • 18. print str[2:5] # Prints characters starting from 3rd to 5th print str[2:] # Prints string starting from 3rd character print str * 2 # Prints string two times print str + "TEST" # Prints concatenated string Output: Hello World! H llo llo World! Hello World!Hello World! Hello World!TEST
  • 19. Python Lists: Lists are the most versatile of Python's compound data types. A list contains items separated by commas and enclosed within square brackets ([]). Example: list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] tinylist = [123, 'john'] print list # Prints complete list print list[0] # Prints first element of the list print list[1:3] # Prints elements starting from 2nd till 3rd print list[2:] # Prints elements starting from 3rd element print tinylist * 2 # Prints list two times print list + tinylist # Prints concatenated lists
  • 20. Python Tuples: A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses. The main differences between lists and tuples are: Lists are enclosed in brackets ( [ ] ) and their elements and size can be changed, while tuples are enclosed in parentheses ( ( ) ) and cannot be updated. Example: tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) tinytuple = (123, 'john')
  • 21. print tuple # Prints complete list print tuple[0] # Prints first element of the list print tuple[1:3] # Prints elements starting from 2nd till 3rd print tuple[2:] # Prints elements starting from 3rd element print tinytuple * 2 # Prints list two times print tuple + tinytuple # Prints concatenated lists Output: ('abcd', 786, 2.23, 'john', 70.200000000000003) abcd (786, 2.23)
  • 22. (2.23, 'john', 70.200000000000003) (123, 'john', 123, 'john') ('abcd', 786, 2.23, 'john', 70.200000000000003, 123, 'john') Following is invalid with tuple, because we attempted to update a tuple, which is not allowed. Similar case is possible with lists: tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 ) list = [ 'abcd', 786 , 2.23, 'john', 70.2 ] tuple[2] = 1000 # Invalid syntax with tuple list[2] = 1000 # Valid syntax with list
  • 23. Python Dictionary: Python's dictionaries are kind of hash table type. They work like associative arrays or hashes found in Perl and consist of key-value pairs. A dictionary key are usually numbers or strings. Dictionaries are enclosed by curly braces ( { } ) and values can be assigned and accessed using square braces ( [] ). For example: dict = {} dict['one'] = "This is one" dict[2] = "This is two" tinydict = {'name': 'john','code':6734, 'dept': 'sales'}
  • 24. print dict['one'] # Prints value for 'one' key print dict[2] # Prints value for 2 key print tinydict # Prints complete dictionary print tinydict.keys() # Prints all the keys print tinydict.values() # Prints all the values Output: This is one This is two {'dept': 'sales', 'code': 6734, 'name': 'john'} ['dept', 'code', 'name'] ['sales', 6734, 'john']
  • 25. Operators Simple answer can be given using expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + is called operator. Python language supports the following types of operators. ➢ Arithmetic Operators ➢ Comparison (i.e., Relational) Operators ➢ Assignment Operators ➢ Logical Operators ➢ Bitwise Operators ➢ Membership Operators ➢ Identity Operators
  • 26. Python Arithmetic Operator a = 21 b = 10 C=0 c=a+b print "Line 1 - Value of c is ", c c=a-b print "Line 2 - Value of c is ", c c=a*b print "Line 3 - Value of c is ", c
  • 27. c=a/b print "Line 4 - Value of c is ", c c=a%b print "Line 5 - Value of c is ", c a=2 b=3 c = a**b print "Line 6 - Value of c is ", c a = 10 b=5 c = a//b print "Line 7 - Value of c is ", c
  • 28. Output: Line 1 - Value of c is 31 Line 2 - Value of c is 11 Line 3 - Value of c is 210 Line 4 - Value of c is 2 Line 5 - Value of c is 1 Line 6 - Value of c is 8 Line 7 - Value of c is 2
  • 34. Example: a = 10 b = 20 list = [1, 2, 3, 4, 5 ]; if ( a in list ): print "Line 1 - a is available in the given list" else: print "Line 1 - a is not available in the given list" if ( b not in list ): print "Line 2 - b is not available in the given list" else: print "Line 2 - b is available in the given list"
  • 35. a=2 if ( a in list ): print "Line 3 - a is available in the given list" else: print "Line 3 - a is not available in the given list" Output: Line 1 - a is not available in the given list Line 2 - b is not available in the given list Line 3 - a is available in the given list
  • 37. a = 20 b = 20 if ( a is b ): print "Line 1 - a and b have same identity" else: print "Line 1 - a and b do not have same identity"
  • 38. b = 30 if ( a is b ): print "Line 3 - a and b have same identity" else: print "Line 3 - a and b do not have same identity"
  • 39. if ( a is not b ): print "Line 4 - a and b do not have same identity" else: print "Line 4 - a and b have same identity" Output: Line 1 - a and b have same identity Line 3 - a and b do not have same identity Line 4 - a and b do not have same identity