SlideShare a Scribd company logo
1 of 12
Why Python?
A programming language with strong similarities to PERL, but with powerful typing and object
oriented features. Commonly used for producing HTML content on websites. Great for text files.
◦ Useful built-in types (lists, dictionaries).
◦ Clean syntax, powerful extensions.
Natural Language Toolkit
Ease of use; interpreter
AI Processing: Symbolic
◦ Python’s built-in data types for strings, lists, and more.
◦ Java or C++ require the use of special classes for this.
AI Processing: Statistical
◦ Python has strong numeric processing capabilities: matrix operations, etc.
◦ Suitable for probability and machine learning code.
Learning Python
Unfortunately, we won’t have time to cover all of
Python in class; so, we’re just going to go over ome
highlights.
◦You’ll need to learn more on your own.
◦Homework 0 asks you to install Python or get comfortable
using it here in the lab. It also asks you to read some online
Python tutorials.
◦Later homeworks will include Python programming
exercises to help you practice.
◦We will fairly rapidly move to using the Natural Language
ToolKit.
Installing Python
Python is installed on the PCs in 156.
Python for Win/Mac/Unix/Linux is available from www.python.org.
◦ Generally an easy install.
◦ On macs, already part of OS X.
◦ For NLTK you need Python 2.3 or higher.
GUI development environment: IDLE.
IDLE Development
Environment
Shell for interactive evaluation.
Text editor with color-coding and smart indenting for creating python
files.
Menu commands for changing system settings and running files.
We will use IDLE in class.
Look at a sample of
code…
x = 34 - 23 # A comment.
y = “Hello” # Another one.
z = 3.45
if z == 3.45 or y == “Hello”:
x = x + 1
y = y + “ World” # String concat.
print x
print y
Basic Data types
Integers (default for numbers)
z = 5 / 2 # Answer is 2, integer division.
Floats
x = 3.456
Strings
Can use “” or ‘’ to specify. “abc” ‘abc’ (Same thing.)
Unmatched ones can occur within the string. “matt’s”
Use triple double-quotes for multi-line strings or strings than
contain both ‘ and “ inside of them: “““a‘b“c”””
Whitespace
Whitespace is meaningful in Python: especially
indentation and placement of newlines.
◦Use a newline to end a line of code.
(Not a semicolon like in C++ or Java.)
(Use  when must go to next line prematurely.)
◦No braces { } to mark blocks of code in Python…
Use consistent indentation instead. The first line with a
new indentation is considered outside of the block.
◦Often a colon appears at the start of a new block. (We’ll
see this later for function and class definitions.)
Comments
Start comments with # – the rest of line is ignored.
Can include a “documentation string” as the first line
of any new function or class that you define.
The development environment, debugger, and other
tools use it: it’s good style to include one.
def my_function(x, y):
“““This is the docstring. This
function does blah blah blah.”””
# The code would go here...
Python and Types
Python determines the data types
in a program automatically. “Dynamic Typing”
But Python’s not casual about types, it
enforces them after it figures them out. “Strong Typing”
So, for example, you can’t just append an integer to a string. You
must first convert the integer to a string itself.
x = “the answer is ” # Decides x is string.
y = 23 # Decides y is integer.
print x + y # Python will complain about this.
Naming Rules
Names are case sensitive and cannot start with a
number. They can contain letters, numbers, and
underscores.
bob Bob _bob _2_bob_ bob_2 BoB
There are some reserved words:
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
String Operations
We can use some methods built-in to the string data
type to perform some formatting operations on
strings:
>>> “hello”.upper()
‘HELLO’
There are many other handy string operations
available. Check the Python documentation for more.
Thank you

More Related Content

What's hot

Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1Kanchilug
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installingMohd Sajjad
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPTShivam Gupta
 
What is Python? An overview of Python for science.
What is Python? An overview of Python for science.What is Python? An overview of Python for science.
What is Python? An overview of Python for science.Nicholas Pringle
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming pptismailmrribi
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonSyed Zaid Irshad
 
An Introduction to Python Programming
An Introduction to Python ProgrammingAn Introduction to Python Programming
An Introduction to Python ProgrammingMorteza Zakeri
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask TrainingJanBask Training
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythoneShikshak
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1Kirti Verma
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginnerrajkamaltibacademy
 
Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with pythonPorimol Chandro
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialQA TrainingHub
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonparadisetechsoftsolutions
 
Python basics
Python basicsPython basics
Python basicsJyoti shukla
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To PythonVanessa Rene
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to pythonMohamed Hegazy
 
Seminar report On Python
Seminar report On PythonSeminar report On Python
Seminar report On PythonShivam Gupta
 

What's hot (20)

Python quick guide1
Python quick guide1Python quick guide1
Python quick guide1
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
What is Python? An overview of Python for science.
What is Python? An overview of Python for science.What is Python? An overview of Python for science.
What is Python? An overview of Python for science.
 
Python Programming ppt
Python Programming pptPython Programming ppt
Python Programming ppt
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
An Introduction to Python Programming
An Introduction to Python ProgrammingAn Introduction to Python Programming
An Introduction to Python Programming
 
Introduction about Python by JanBask Training
Introduction about Python by JanBask TrainingIntroduction about Python by JanBask Training
Introduction about Python by JanBask Training
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python final presentation kirti ppt1
Python final presentation kirti ppt1Python final presentation kirti ppt1
Python final presentation kirti ppt1
 
Python Tutorial for Beginner
Python Tutorial for BeginnerPython Tutorial for Beginner
Python Tutorial for Beginner
 
Introduction to programming with python
Introduction to programming with pythonIntroduction to programming with python
Introduction to programming with python
 
Python | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python TutorialPython | What is Python | History of Python | Python Tutorial
Python | What is Python | History of Python | Python Tutorial
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of python
 
Python basics
Python basicsPython basics
Python basics
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
GDG Helwan Introduction to python
GDG Helwan Introduction to pythonGDG Helwan Introduction to python
GDG Helwan Introduction to python
 
Seminar report On Python
Seminar report On PythonSeminar report On Python
Seminar report On Python
 

Similar to Introduction to phython programming

Python Training Topics
Python Training TopicsPython Training Topics
Python Training Topicsvibrantuser
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh MalothBhavsingh Maloth
 
Os Goodger
Os GoodgerOs Goodger
Os Goodgeroscon2007
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxGaneshRaghu4
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
Python: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersPython: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersGlenn De Backer
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way PresentationAmira ElSharkawy
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
Python PPT.pptx
Python PPT.pptxPython PPT.pptx
Python PPT.pptxJosephMuez2
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
 

Similar to Introduction to phython programming (20)

Python Training Topics
Python Training TopicsPython Training Topics
Python Training Topics
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Pythonintro
PythonintroPythonintro
Pythonintro
 
Os Goodger
Os GoodgerOs Goodger
Os Goodger
 
Python ppt
Python pptPython ppt
Python ppt
 
Module 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptxModule 1 - Programming Fundamentals.pptx
Module 1 - Programming Fundamentals.pptx
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
Python for katana
Python for katanaPython for katana
Python for katana
 
How To Tame Python
How To Tame PythonHow To Tame Python
How To Tame Python
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
Python: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersPython: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopers
 
Learn Python The Hard Way Presentation
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
 
Python Session - 2
Python Session - 2Python Session - 2
Python Session - 2
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Python PPT.pptx
Python PPT.pptxPython PPT.pptx
Python PPT.pptx
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
python and perl
python and perlpython and perl
python and perl
 

More from ASIT Education

COMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETSCOMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETSASIT Education
 
Simple hardware problems facing in pc's
Simple hardware problems facing in pc'sSimple hardware problems facing in pc's
Simple hardware problems facing in pc'sASIT Education
 
Amc square IT services
Amc square IT servicesAmc square IT services
Amc square IT servicesASIT Education
 
learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.ASIT Education
 
Learn my sql at amc square learning
Learn my sql at amc square learningLearn my sql at amc square learning
Learn my sql at amc square learningASIT Education
 
Learn joomla at amc square learning
Learn joomla at amc square learningLearn joomla at amc square learning
Learn joomla at amc square learningASIT Education
 
learn ANDROID at AMC Square Learning
learn ANDROID at AMC Square Learninglearn ANDROID at AMC Square Learning
learn ANDROID at AMC Square LearningASIT Education
 
Learn spring at amc square learning
Learn spring at amc square learningLearn spring at amc square learning
Learn spring at amc square learningASIT Education
 
Learn cpp at amc square learning
Learn cpp at amc square learningLearn cpp at amc square learning
Learn cpp at amc square learningASIT Education
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learningASIT Education
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learningASIT Education
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningASIT Education
 
learn sharepoint at AMC Square learning
learn sharepoint at AMC Square learninglearn sharepoint at AMC Square learning
learn sharepoint at AMC Square learningASIT Education
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testingASIT Education
 
C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.pptASIT Education
 
Ruby programming introduction
Ruby programming introductionRuby programming introduction
Ruby programming introductionASIT Education
 
Introduction to vm ware
Introduction to vm wareIntroduction to vm ware
Introduction to vm wareASIT Education
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testingASIT Education
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programmingASIT Education
 
Introduction to internet
Introduction to internetIntroduction to internet
Introduction to internetASIT Education
 

More from ASIT Education (20)

COMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETSCOMMON PROBLEMS FACING WITH TABLETS
COMMON PROBLEMS FACING WITH TABLETS
 
Simple hardware problems facing in pc's
Simple hardware problems facing in pc'sSimple hardware problems facing in pc's
Simple hardware problems facing in pc's
 
Amc square IT services
Amc square IT servicesAmc square IT services
Amc square IT services
 
learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.learn JAVA at ASIT with a placement assistance.
learn JAVA at ASIT with a placement assistance.
 
Learn my sql at amc square learning
Learn my sql at amc square learningLearn my sql at amc square learning
Learn my sql at amc square learning
 
Learn joomla at amc square learning
Learn joomla at amc square learningLearn joomla at amc square learning
Learn joomla at amc square learning
 
learn ANDROID at AMC Square Learning
learn ANDROID at AMC Square Learninglearn ANDROID at AMC Square Learning
learn ANDROID at AMC Square Learning
 
Learn spring at amc square learning
Learn spring at amc square learningLearn spring at amc square learning
Learn spring at amc square learning
 
Learn cpp at amc square learning
Learn cpp at amc square learningLearn cpp at amc square learning
Learn cpp at amc square learning
 
Learn perl in amc square learning
Learn perl in amc square learningLearn perl in amc square learning
Learn perl in amc square learning
 
Learn c sharp at amc square learning
Learn c sharp at amc square learningLearn c sharp at amc square learning
Learn c sharp at amc square learning
 
Learn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square LearningLearn Ruby Programming in Amc Square Learning
Learn Ruby Programming in Amc Square Learning
 
learn sharepoint at AMC Square learning
learn sharepoint at AMC Square learninglearn sharepoint at AMC Square learning
learn sharepoint at AMC Square learning
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
C programmimng basic.ppt
C programmimng basic.pptC programmimng basic.ppt
C programmimng basic.ppt
 
Ruby programming introduction
Ruby programming introductionRuby programming introduction
Ruby programming introduction
 
Introduction to vm ware
Introduction to vm wareIntroduction to vm ware
Introduction to vm ware
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
Introduction to internet
Introduction to internetIntroduction to internet
Introduction to internet
 

Recently uploaded

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Recently uploaded (20)

Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1CĂłdigo Creativo y Arte de Software | Unidad 1
CĂłdigo Creativo y Arte de Software | Unidad 1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Introduction to phython programming

  • 1. Why Python? A programming language with strong similarities to PERL, but with powerful typing and object oriented features. Commonly used for producing HTML content on websites. Great for text files. ◦ Useful built-in types (lists, dictionaries). ◦ Clean syntax, powerful extensions. Natural Language Toolkit Ease of use; interpreter AI Processing: Symbolic ◦ Python’s built-in data types for strings, lists, and more. ◦ Java or C++ require the use of special classes for this. AI Processing: Statistical ◦ Python has strong numeric processing capabilities: matrix operations, etc. ◦ Suitable for probability and machine learning code.
  • 2. Learning Python Unfortunately, we won’t have time to cover all of Python in class; so, we’re just going to go over ome highlights. ◦You’ll need to learn more on your own. ◦Homework 0 asks you to install Python or get comfortable using it here in the lab. It also asks you to read some online Python tutorials. ◦Later homeworks will include Python programming exercises to help you practice. ◦We will fairly rapidly move to using the Natural Language ToolKit.
  • 3. Installing Python Python is installed on the PCs in 156. Python for Win/Mac/Unix/Linux is available from www.python.org. ◦ Generally an easy install. ◦ On macs, already part of OS X. ◦ For NLTK you need Python 2.3 or higher. GUI development environment: IDLE.
  • 4. IDLE Development Environment Shell for interactive evaluation. Text editor with color-coding and smart indenting for creating python files. Menu commands for changing system settings and running files. We will use IDLE in class.
  • 5. Look at a sample of code… x = 34 - 23 # A comment. y = “Hello” # Another one. z = 3.45 if z == 3.45 or y == “Hello”: x = x + 1 y = y + “ World” # String concat. print x print y
  • 6. Basic Data types Integers (default for numbers) z = 5 / 2 # Answer is 2, integer division. Floats x = 3.456 Strings Can use “” or ‘’ to specify. “abc” ‘abc’ (Same thing.) Unmatched ones can occur within the string. “matt’s” Use triple double-quotes for multi-line strings or strings than contain both ‘ and “ inside of them: “““a‘b“c”””
  • 7. Whitespace Whitespace is meaningful in Python: especially indentation and placement of newlines. ◦Use a newline to end a line of code. (Not a semicolon like in C++ or Java.) (Use when must go to next line prematurely.) ◦No braces { } to mark blocks of code in Python… Use consistent indentation instead. The first line with a new indentation is considered outside of the block. ◦Often a colon appears at the start of a new block. (We’ll see this later for function and class definitions.)
  • 8. Comments Start comments with # – the rest of line is ignored. Can include a “documentation string” as the first line of any new function or class that you define. The development environment, debugger, and other tools use it: it’s good style to include one. def my_function(x, y): “““This is the docstring. This function does blah blah blah.””” # The code would go here...
  • 9. Python and Types Python determines the data types in a program automatically. “Dynamic Typing” But Python’s not casual about types, it enforces them after it figures them out. “Strong Typing” So, for example, you can’t just append an integer to a string. You must first convert the integer to a string itself. x = “the answer is ” # Decides x is string. y = 23 # Decides y is integer. print x + y # Python will complain about this.
  • 10. Naming Rules Names are case sensitive and cannot start with a number. They can contain letters, numbers, and underscores. bob Bob _bob _2_bob_ bob_2 BoB There are some reserved words: 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
  • 11. String Operations We can use some methods built-in to the string data type to perform some formatting operations on strings: >>> “hello”.upper() ‘HELLO’ There are many other handy string operations available. Check the Python documentation for more.