SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming LanguageDipankar Achinta
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1Nicholas I
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming LanguageTahani Al-Manie
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaEdureka!
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data typesMohd Sajjad
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaEdureka!
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| FundamentalsMohd Sajjad
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Edureka!
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaEdureka!
 

La actualidad más candente (20)

Python ppt
Python pptPython ppt
Python ppt
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Intro to Python Programming Language
Intro to Python Programming LanguageIntro to Python Programming Language
Intro to Python Programming Language
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Python basics
Python basicsPython basics
Python basics
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Get started python programming part 1
Get started python programming   part 1Get started python programming   part 1
Get started python programming part 1
 
Python 3 Programming Language
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Python ppt
Python pptPython ppt
Python ppt
 
Python made easy
Python made easy Python made easy
Python made easy
 
Python-03| Data types
Python-03| Data typesPython-03| Data types
Python-03| Data types
 
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | EdurekaPython Course | Python Programming | Python Tutorial | Python Training | Edureka
Python Course | Python Programming | Python Tutorial | Python Training | Edureka
 
Python-01| Fundamentals
Python-01| FundamentalsPython-01| Fundamentals
Python-01| Fundamentals
 
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...Learn Python Programming | Python Programming - Step by Step | Python for Beg...
Learn Python Programming | Python Programming - Step by Step | Python for Beg...
 
Python ppt
Python pptPython ppt
Python ppt
 
Python
PythonPython
Python
 
Python Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | EdurekaPython Basics | Python Tutorial | Edureka
Python Basics | Python Tutorial | Edureka
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 

Destacado

πετρινα γεφυρια (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
 

Destacado (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 a 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
 
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
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumarSujith Kumar
 

Similar a 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
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
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 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
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 

Más de Aswin Krishnamoorthy

Más de 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
 

Último

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfChristalin Nelson
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptxAneriPatwari
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 

Último (20)

Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
Indexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdfIndexing Structures in Database Management system.pdf
Indexing Structures in Database Management system.pdf
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
ARTERIAL BLOOD GAS ANALYSIS........pptx
ARTERIAL BLOOD  GAS ANALYSIS........pptxARTERIAL BLOOD  GAS ANALYSIS........pptx
ARTERIAL BLOOD GAS ANALYSIS........pptx
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 

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