ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
PYTHON PROGRAMMING
Department of computer science
• Introduction to Python and installation:
• Python is a widely used general-purpose, high level
programming language. It was initially designed by
Guido van Rossum in 1991 and developed by Python
Software Foundation. It was mainly developed for
emphasis on code readability, and its syntax allows
programmers to express concepts in fewer lines of
code. Python is a programming language that lets
you work quickly and integrate systems more
efficiently. There are two major Python versions-
Python 2 and Python 3.
• • On 16 October 2000, Python 2.0 was released with
many new features.
• • On 3rd December 2008, Python 3.0 was released
with more testing and includes new features.
• Beginning with Python programming:
• 1) Finding an Interpreter:
• Before we start Python programming, we need to
have an interpreter to interpret and run our
programs. There are certain online interpreters like
https://ide.geeksforgeeks.org/,
http://ideone.com/ or http://codepad.org/ that
can be used to start Python without installing an
interpreter.
• Windows: There are many interpreters available
freely to run Python scripts like IDLE (Integrated
Development Environment) which is installed
when you install the python software from
http://python.org/downloads/
• 2) Writing first program:
• # Script Begins
• Statement1
• Statement2
• Statement3
• # Script Ends
• Why to use Python:
• The following are the primary factors to
use python in day-to-day life:
• 1. Python is object-oriented
• Structure supports such concepts as
polymorphism, operation overloading and
multiple inheritance.
• 2. Indentation
• Indentation is one of the greatest feature
in python
• 3. It’s free (open source)
• Downloading python and installing python is free and
easy
• 4. It’s Powerful
• Dynamic typing
• Built-in types and tools
• Library utilities
• Third party utilities (e.g. Numeric, NumPy, sciPy)
• Automatic memory management
• 5. It’s Portable
• Python runs virtually every major platform used today
• As long as you have a compatable python interpreter
installed, python programs will run in exactly the same
manner, irrespective of platform.
• 6. It’s easy to use and learn
• No intermediate compile
• Python Programs are compiled automatically to an intermediate form
called byte code, which the interpreter then reads.
• This gives python the development speed of an interpreter without
the performance loss inherent in purely interpreted languages.
• Structure and syntax are pretty intuitive and easy to grasp.
• 7. Interpreted Language
• Python is processed at runtime by python Interpreter
• 8. Interactive Programming Language
• Users can interact with the python interpreter directly for writing the
programs
• 9. Straight forward syntax
• The formation of python syntax is simple and straight forward which
also makes it popular.
• Installation:
• There are many interpreters available freely to
run Python scripts like IDLE (Integrated
Development Environment) which is installed
when you install the python software from
http://python.org/downloads/
• Steps to be followed and remembered:
• Step 1: Select Version of Python to Install. Step 2:
Download Python Executable Installer. Step 3:
Run Executable Installer.
• Step 4: Verify Python Was Installed On Windows.
• Step 5: Verify Pip Was Installed. Step 6:
Add Python Path to Environment Variables
(Optional)
• Working with Python Python Code Execution:
• Python’s traditional runtime execution
model:Source code you type is translated to byte
code, which is then run by the Python Virtual
Machine (PVM). Your code is automatically
compiled, but then it is interpreted.
• There are two modes for using the Python
interpreter:
• • Interactive Mode
• • Script Mode
• Running Python in interactive mode: Without passing
python script file to the interpreter, directly execute
code to Python prompt.
• Once you‟re inside the python interpreter, then you
can start.
• >>> print("hello world")
• hello world
• #Relevant output is displayed on subsequent lines
without the >>> symbol
• >>> x=[0,1,2]
• #Quantities stored in memory are not displayed by
default.
• >>> x
• #If a quantity is stored in memory, typing its name will
display it. [0, 1, 2]
• >>> 2+3 5
The chevron at the beginning of the 1st line, i.e., the symbol >>> is a prompt the
python interpreter uses to indicate that it is ready. If the programmer types 2+6,
the interpreter replies 8.
• Running Python in script mode:
• Alternatively, programmers can store Python script
source code in a file with the .py extension, and use the
interpreter to execute the contents of the file. To
execute the script by the interpreter, you have to tell
the interpreter the name of the file. For example, if you
have a script name MyFile.py and you're working on
Unix, to run the script you have to type:
• python MyFile.py
• Working with the interactive mode is better when
Python programmers deal with small pieces of code as
you can type and execute them immediately, but when
the code is more than 2-4 lines, using the script for
coding can help to modify and use the code in future.
• Example:
PYTHON PROGRAMMING.pptx
• Numeric Data types:
• The data stored in memory can be of many types.
For example, a student roll number is stored as a
numeric value and his or her address is stored as
alphanumeric characters. Python has various
standard data types that are used to define the
operations possible on them and the storage
method for each of them.
• Int:
• Int, or integer, is a whole number, positive or
negative, without decimals, of unlimited length.
• >>> print(24656354687654+2)
• 24656354687656
• >>> print(20)
• 20
• # To verify the type of any object in
Python, use the type() function:
• >>> type(10)
• <class 'int'>
• >>> a=11
• >>> print(type(a))
• <class 'int'>
• Float:
• Float, or "floating point number" is a number,
positive or negative, containing one or more
decimals.
• Float can also be scientific numbers with an "e" to
indicate the power of 10.
• >>> y=2.8
• >>> y
• 2.8
• >>> y=2.8
• >>> print(type(y))
• <class 'float'>
• >>> type(.4)
• <class 'float'>
• >>> 2.
• 2.0
• Example:
• x = 35e3
• y = 12E4
• z = -87.7e100
• print(type(x))
• print(type(y))
• print(type(z))
• Output:
• <class 'float'>
• <class 'float‘>
• <class 'float'>
• Boolean:
• Objects of Boolean type may have one of
two values, True or False:
• >>> type(True)
• <class 'bool'>
• >>> type(False)
• <class 'bool'>
• String:
• 1. Strings in Python are identified as a contiguous set
of characters represented in the quotation marks.
Python allows for either pairs of single or double
quotes.
• • 'hello' is the same as "hello".
• • Strings can be output to screen using the print
function.
• For example: print("hello").
• >>> print(“VSR college") VSR college
• >>> type(“VSR college")
• <class 'str'>
• >>> print(‘VSR college')
• VSR college
• >>> " "
• ' '
• A string is a group/a sequence of characters. Since
Python has no provision for arrays, we simply use
strings. This is how we declare a string. We can use
a pair of single or double quotes. Every string
object is of the type „str‟.
• >>> type("name")
• <class 'str'>
• fruit = 'banana'
• >>> letter = fruit[1]
• The second statement selects character number 1
from fruit and assigns it to letter. The expression in
brackets is called an index. The index indicates
which character in the sequence we want
• String slices:
• A segment of a string is called a slice.
Selecting a slice is similar to selecting a
character: 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. Slice out substrings, sub lists, sub Tuples
using index. Syntax:[Start: stop: steps]
• Slicing will start from index and will go up to
stop in step of steps.
• Default value of start is 0,
• Stop is last index of list
• And for step default is 1
• For example 1−
• str = 'Hello World!'
• print str
• # Prints complete string
• print str[0]
• # 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
• Example 2:
• >>> x='computer'
• >>> x[1:4]
• 'omp'
• >>> x[3:]
• 'puter'
• >>> x[:5]
• 'compu'
• >>> x[-1]
• 'r'
• >>> x[-3:]
• 'ter'
• >>> x[:-2]
• 'comput'
• >>> x[::-2]
• 'rtpo'
• >>> x[::-1]
• 'retupmoc'
• Immutability:
• It is tempting to use the [] operator on the left side of an
assignment, with the intention of changing a character in
a string.
• For example:
• >>> greeting=‘VSR college!'
• >>> greeting[0]='n'
• TypeError: 'str' object does not support item assignment
The reason for the error is that strings are immutable,
which means we can‟t change an existing string.
• The best we can do is creating a new string that is a
variation on the original:
• >>> greeting = 'Hello, world!'
• >>>new_greeting = 'J' + greeting[1:]
• >>>new_greeting
• 'Jello, world!'
• Note: The plus (+) sign is the string concatenation
operator and the asterisk (*) is the repetition operator
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
• Note: All the string methods will be returning
either true or false as the result
• 1. isalnum():
• Isalnum() method returns true if string has at
least 1 character and all characters are
alphanumeric and false otherwise.
• Syntax:
• String.isalnum()
• Example:
• >>> string="123alpha"
• >>>string.isalnum()
• True
• 2. isalpha():
• isalpha() method returns true if string has
at least 1 character and all characters are
alphabetic and false otherwise.
• Syntax:
• String.isalpha()
• Example:
• >>> string="nikhil"
• >>>string.isalpha()
• True
• 3. isdigit():
• isdigit() returns true if string contains only
digits and false otherwise.
• Syntax:
• String.isdigit()
• Example:
• >>> string="123456789"
• >>>string.isdigit()
• True
• 3. isdigit():
• isdigit() returns true if string contains only
digits and false otherwise.
• Syntax:
• String.isdigit()
• Example:
• >>> string="123456789"
• >>>string.isdigit()
• True
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx
PYTHON PROGRAMMING.pptx

More Related Content

Similar to PYTHON PROGRAMMING.pptx (20)

python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
MohammadSamiuddin10
Ìý
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
MohammadSamiuddin10
Ìý
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
Ìý
#Code2Create: Python Basics
#Code2Create: Python Basics#Code2Create: Python Basics
#Code2Create: Python Basics
GDGKuwaitGoogleDevel
Ìý
Introduction to Python for Bioinformatics
Introduction to Python for BioinformaticsIntroduction to Python for Bioinformatics
Introduction to Python for Bioinformatics
José Héctor Gálvez
Ìý
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
gmadhu8
Ìý
Python 01.pptx
Python 01.pptxPython 01.pptx
Python 01.pptx
AliMohammadAmiri
Ìý
Python Introduction
Python IntroductionPython Introduction
Python Introduction
Punithavel Ramani
Ìý
Python
PythonPython
Python
Shivam Gupta
Ìý
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
Ìý
Python_Programming_PPT Basics of python programming language
Python_Programming_PPT   Basics of python programming languagePython_Programming_PPT   Basics of python programming language
Python_Programming_PPT Basics of python programming language
earningmoney9595
Ìý
Python unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming contentPython unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming content
swarna16
Ìý
Python programming
Python programmingPython programming
Python programming
saroja20
Ìý
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
Ahmet Bulut
Ìý
Introduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE IntegrationIntroduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
Ìý
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
ansariparveen06
Ìý
Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
SanjeedaPraween
Ìý
4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx
Gnanesh12
Ìý
Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...
ahmedosman389
Ìý
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
Ìý
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
2022-23TYBSC(CS)-Python Prog._Chapter-1.pptx
sangeeta borde
Ìý
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
gmadhu8
Ìý
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
Ìý
Python_Programming_PPT Basics of python programming language
Python_Programming_PPT   Basics of python programming languagePython_Programming_PPT   Basics of python programming language
Python_Programming_PPT Basics of python programming language
earningmoney9595
Ìý
Python unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming contentPython unit 2 is added. Has python related programming content
Python unit 2 is added. Has python related programming content
swarna16
Ìý
Python programming
Python programmingPython programming
Python programming
saroja20
Ìý
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
Ahmet Bulut
Ìý
Introduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE IntegrationIntroduction to Python Basics for PSSE Integration
Introduction to Python Basics for PSSE Integration
FarhanKhan978284
Ìý
presentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptxpresentation_python_7_1569170870_375360.pptx
presentation_python_7_1569170870_375360.pptx
ansariparveen06
Ìý
Class_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdfClass_X_PYTHON_J.pdf
Class_X_PYTHON_J.pdf
SanjeedaPraween
Ìý
4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx4_Introduction to Python Programming.pptx
4_Introduction to Python Programming.pptx
Gnanesh12
Ìý
Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...Python-Beginer-PartOnePython is one of the top programming languages in the w...
Python-Beginer-PartOnePython is one of the top programming languages in the w...
ahmedosman389
Ìý
Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.Basic concept of Python.pptx includes design tool, identifier, variables.
Basic concept of Python.pptx includes design tool, identifier, variables.
supriyasarkar38
Ìý

More from swarna627082 (6)

jghj.pptjghj.ppt
jghj.ppt
swarna627082
Ìý
dgp.pptx
dgp.pptxdgp.pptx
dgp.pptx
swarna627082
Ìý
dsfkh.pptx
dsfkh.pptxdsfkh.pptx
dsfkh.pptx
swarna627082
Ìý
dsf.pptx
dsf.pptxdsf.pptx
dsf.pptx
swarna627082
Ìý
ababc.pptx
ababc.pptxababc.pptx
ababc.pptx
swarna627082
Ìý
Data and Information.docx
Data and Information.docxData and Information.docx
Data and Information.docx
swarna627082
Ìý
jghj.pptjghj.ppt
jghj.ppt
swarna627082
Ìý
Data and Information.docx
Data and Information.docxData and Information.docx
Data and Information.docx
swarna627082
Ìý

Recently uploaded (20)

Computer Application in Business (commerce)
Computer Application in Business (commerce)Computer Application in Business (commerce)
Computer Application in Business (commerce)
Sudar Sudar
Ìý
How to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 EmployeeHow to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 Employee
Celine George
Ìý
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
sandynavergas1
Ìý
Modeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptxModeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptx
maribethlacno2
Ìý
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir DotanThe Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
History of Stoke Newington
Ìý
Year 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptxYear 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptx
mansk2
Ìý
TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...
TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...
TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...
RizaBedayo
Ìý
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
Ìý
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
Ìý
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
Ìý
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣsHow to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
Celine George
Ìý
CBSE Arabic Grammar - Class 10 ppt.pptx
CBSE Arabic Grammar - Class 10   ppt.pptxCBSE Arabic Grammar - Class 10   ppt.pptx
CBSE Arabic Grammar - Class 10 ppt.pptx
suhail849886
Ìý
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
A PPT Presentation on The Princess and the God: A tale of ancient India  by A...A PPT Presentation on The Princess and the God: A tale of ancient India  by A...
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
Beena E S
Ìý
The Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom WalkerThe Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom Walker
History of Stoke Newington
Ìý
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
Ìý
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
Ìý
PUBH1000 Module 3: Public Health Systems
PUBH1000 Module 3: Public Health SystemsPUBH1000 Module 3: Public Health Systems
PUBH1000 Module 3: Public Health Systems
Jonathan Hallett
Ìý
The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .
saanidhyapatel09
Ìý
Mate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptxMate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptx
Liny Jenifer
Ìý
Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025Kaun TALHA quiz Prelims - El Dorado 2025
Kaun TALHA quiz Prelims - El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
Ìý
Computer Application in Business (commerce)
Computer Application in Business (commerce)Computer Application in Business (commerce)
Computer Application in Business (commerce)
Sudar Sudar
Ìý
How to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 EmployeeHow to Configure Flexible Working Schedule in Odoo 18 Employee
How to Configure Flexible Working Schedule in Odoo 18 Employee
Celine George
Ìý
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
Eng7-Q4-Lesson 1 Part 1 Understanding Discipline-Specific Words, Voice, and T...
sandynavergas1
Ìý
Modeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptxModeling-Simple-Equation-Using-Bar-Models.pptx
Modeling-Simple-Equation-Using-Bar-Models.pptx
maribethlacno2
Ìý
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir DotanThe Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
The Battle of Belgrade Road: A WW1 Street Renaming Saga by Amir Dotan
History of Stoke Newington
Ìý
Year 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptxYear 10 The Senior Phase Session 3 Term 1.pptx
Year 10 The Senior Phase Session 3 Term 1.pptx
mansk2
Ìý
TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...
TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...
TLE 7 - 3rd Topic - Hand Tools, Power Tools, Instruments, and Equipment Used ...
RizaBedayo
Ìý
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
Ìý
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
Ìý
Computer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network LayerComputer Network Unit IV - Lecture Notes - Network Layer
Computer Network Unit IV - Lecture Notes - Network Layer
Murugan146644
Ìý
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣsHow to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
How to Setup WhatsApp in Odoo 17 - Odoo ºÝºÝߣs
Celine George
Ìý
CBSE Arabic Grammar - Class 10 ppt.pptx
CBSE Arabic Grammar - Class 10   ppt.pptxCBSE Arabic Grammar - Class 10   ppt.pptx
CBSE Arabic Grammar - Class 10 ppt.pptx
suhail849886
Ìý
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
A PPT Presentation on The Princess and the God: A tale of ancient India  by A...A PPT Presentation on The Princess and the God: A tale of ancient India  by A...
A PPT Presentation on The Princess and the God: A tale of ancient India by A...
Beena E S
Ìý
The Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom WalkerThe Story Behind the Abney Park Restoration Project by Tom Walker
The Story Behind the Abney Park Restoration Project by Tom Walker
History of Stoke Newington
Ìý
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
Ìý
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
Ìý
PUBH1000 Module 3: Public Health Systems
PUBH1000 Module 3: Public Health SystemsPUBH1000 Module 3: Public Health Systems
PUBH1000 Module 3: Public Health Systems
Jonathan Hallett
Ìý
The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .The Constitution, Government and Law making bodies .
The Constitution, Government and Law making bodies .
saanidhyapatel09
Ìý
Mate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptxMate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptx
Liny Jenifer
Ìý

PYTHON PROGRAMMING.pptx

  • 2. • Introduction to Python and installation: • Python is a widely used general-purpose, high level programming language. It was initially designed by Guido van Rossum in 1991 and developed by Python Software Foundation. It was mainly developed for emphasis on code readability, and its syntax allows programmers to express concepts in fewer lines of code. Python is a programming language that lets you work quickly and integrate systems more efficiently. There are two major Python versions- Python 2 and Python 3. • • On 16 October 2000, Python 2.0 was released with many new features. • • On 3rd December 2008, Python 3.0 was released with more testing and includes new features.
  • 3. • Beginning with Python programming: • 1) Finding an Interpreter: • Before we start Python programming, we need to have an interpreter to interpret and run our programs. There are certain online interpreters like https://ide.geeksforgeeks.org/, http://ideone.com/ or http://codepad.org/ that can be used to start Python without installing an interpreter. • Windows: There are many interpreters available freely to run Python scripts like IDLE (Integrated Development Environment) which is installed when you install the python software from http://python.org/downloads/
  • 4. • 2) Writing first program: • # Script Begins • Statement1 • Statement2 • Statement3 • # Script Ends
  • 5. • Why to use Python: • The following are the primary factors to use python in day-to-day life: • 1. Python is object-oriented • Structure supports such concepts as polymorphism, operation overloading and multiple inheritance. • 2. Indentation • Indentation is one of the greatest feature in python
  • 6. • 3. It’s free (open source) • Downloading python and installing python is free and easy • 4. It’s Powerful • Dynamic typing • Built-in types and tools • Library utilities • Third party utilities (e.g. Numeric, NumPy, sciPy) • Automatic memory management • 5. It’s Portable • Python runs virtually every major platform used today • As long as you have a compatable python interpreter installed, python programs will run in exactly the same manner, irrespective of platform.
  • 7. • 6. It’s easy to use and learn • No intermediate compile • Python Programs are compiled automatically to an intermediate form called byte code, which the interpreter then reads. • This gives python the development speed of an interpreter without the performance loss inherent in purely interpreted languages. • Structure and syntax are pretty intuitive and easy to grasp. • 7. Interpreted Language • Python is processed at runtime by python Interpreter • 8. Interactive Programming Language • Users can interact with the python interpreter directly for writing the programs • 9. Straight forward syntax • The formation of python syntax is simple and straight forward which also makes it popular.
  • 8. • Installation: • There are many interpreters available freely to run Python scripts like IDLE (Integrated Development Environment) which is installed when you install the python software from http://python.org/downloads/ • Steps to be followed and remembered: • Step 1: Select Version of Python to Install. Step 2: Download Python Executable Installer. Step 3: Run Executable Installer. • Step 4: Verify Python Was Installed On Windows.
  • 9. • Step 5: Verify Pip Was Installed. Step 6: Add Python Path to Environment Variables (Optional)
  • 10. • Working with Python Python Code Execution: • Python’s traditional runtime execution model:Source code you type is translated to byte code, which is then run by the Python Virtual Machine (PVM). Your code is automatically compiled, but then it is interpreted.
  • 11. • There are two modes for using the Python interpreter: • • Interactive Mode • • Script Mode
  • 12. • Running Python in interactive mode: Without passing python script file to the interpreter, directly execute code to Python prompt. • Once you‟re inside the python interpreter, then you can start. • >>> print("hello world") • hello world • #Relevant output is displayed on subsequent lines without the >>> symbol • >>> x=[0,1,2] • #Quantities stored in memory are not displayed by default. • >>> x • #If a quantity is stored in memory, typing its name will display it. [0, 1, 2] • >>> 2+3 5
  • 13. The chevron at the beginning of the 1st line, i.e., the symbol >>> is a prompt the python interpreter uses to indicate that it is ready. If the programmer types 2+6, the interpreter replies 8.
  • 14. • Running Python in script mode: • Alternatively, programmers can store Python script source code in a file with the .py extension, and use the interpreter to execute the contents of the file. To execute the script by the interpreter, you have to tell the interpreter the name of the file. For example, if you have a script name MyFile.py and you're working on Unix, to run the script you have to type: • python MyFile.py • Working with the interactive mode is better when Python programmers deal with small pieces of code as you can type and execute them immediately, but when the code is more than 2-4 lines, using the script for coding can help to modify and use the code in future. • Example:
  • 16. • Numeric Data types: • The data stored in memory can be of many types. For example, a student roll number is stored as a numeric value and his or her address is stored as alphanumeric characters. Python has various standard data types that are used to define the operations possible on them and the storage method for each of them. • Int: • Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length. • >>> print(24656354687654+2) • 24656354687656 • >>> print(20) • 20
  • 17. • # To verify the type of any object in Python, use the type() function: • >>> type(10) • <class 'int'> • >>> a=11 • >>> print(type(a)) • <class 'int'>
  • 18. • Float: • Float, or "floating point number" is a number, positive or negative, containing one or more decimals. • Float can also be scientific numbers with an "e" to indicate the power of 10. • >>> y=2.8 • >>> y • 2.8 • >>> y=2.8 • >>> print(type(y)) • <class 'float'> • >>> type(.4) • <class 'float'>
  • 19. • >>> 2. • 2.0 • Example: • x = 35e3 • y = 12E4 • z = -87.7e100 • print(type(x)) • print(type(y)) • print(type(z)) • Output: • <class 'float'> • <class 'float‘> • <class 'float'>
  • 20. • Boolean: • Objects of Boolean type may have one of two values, True or False: • >>> type(True) • <class 'bool'> • >>> type(False) • <class 'bool'>
  • 21. • String: • 1. Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python allows for either pairs of single or double quotes. • • 'hello' is the same as "hello". • • Strings can be output to screen using the print function. • For example: print("hello"). • >>> print(“VSR college") VSR college • >>> type(“VSR college") • <class 'str'> • >>> print(‘VSR college') • VSR college • >>> " " • ' '
  • 22. • A string is a group/a sequence of characters. Since Python has no provision for arrays, we simply use strings. This is how we declare a string. We can use a pair of single or double quotes. Every string object is of the type „str‟. • >>> type("name") • <class 'str'> • fruit = 'banana' • >>> letter = fruit[1] • The second statement selects character number 1 from fruit and assigns it to letter. The expression in brackets is called an index. The index indicates which character in the sequence we want
  • 23. • String slices: • A segment of a string is called a slice. Selecting a slice is similar to selecting a character: 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. Slice out substrings, sub lists, sub Tuples using index. Syntax:[Start: stop: steps] • Slicing will start from index and will go up to stop in step of steps. • Default value of start is 0,
  • 24. • Stop is last index of list • And for step default is 1 • For example 1− • str = 'Hello World!' • print str • # Prints complete string • print str[0] • # 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
  • 25. • Output: • Hello World! • H • llo • llo World! • Hello World!Hello World! • Hello World!TEST
  • 26. • Example 2: • >>> x='computer' • >>> x[1:4] • 'omp' • >>> x[3:] • 'puter' • >>> x[:5] • 'compu' • >>> x[-1] • 'r' • >>> x[-3:] • 'ter' • >>> x[:-2] • 'comput' • >>> x[::-2] • 'rtpo' • >>> x[::-1] • 'retupmoc'
  • 27. • Immutability: • It is tempting to use the [] operator on the left side of an assignment, with the intention of changing a character in a string. • For example: • >>> greeting=‘VSR college!' • >>> greeting[0]='n' • TypeError: 'str' object does not support item assignment The reason for the error is that strings are immutable, which means we can‟t change an existing string. • The best we can do is creating a new string that is a variation on the original: • >>> greeting = 'Hello, world!' • >>>new_greeting = 'J' + greeting[1:] • >>>new_greeting • 'Jello, world!' • Note: The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator
  • 30. • Note: All the string methods will be returning either true or false as the result • 1. isalnum(): • Isalnum() method returns true if string has at least 1 character and all characters are alphanumeric and false otherwise. • Syntax: • String.isalnum() • Example: • >>> string="123alpha" • >>>string.isalnum() • True
  • 31. • 2. isalpha(): • isalpha() method returns true if string has at least 1 character and all characters are alphabetic and false otherwise. • Syntax: • String.isalpha() • Example: • >>> string="nikhil" • >>>string.isalpha() • True
  • 32. • 3. isdigit(): • isdigit() returns true if string contains only digits and false otherwise. • Syntax: • String.isdigit() • Example: • >>> string="123456789" • >>>string.isdigit() • True
  • 33. • 3. isdigit(): • isdigit() returns true if string contains only digits and false otherwise. • Syntax: • String.isdigit() • Example: • >>> string="123456789" • >>>string.isdigit() • True