SlideShare une entreprise Scribd logo
1  sur  13
Introduction to Python
Why Python?
• Python is
• easy to learn,
• relatively fast,
• object-oriented,
• strongly typed,
• widely used, and
• portable.
• C is much faster but much
harder to use.
• Java is about as fast and slightly
harder to use.
• Perl is slower, is as easy to use,
but is not strongly typed.
Getting started on the Mac
• Start a terminal session.
• Type “python”
• This should start the Python interpreter
> python
Python 2.4.2 (#2, Apr 10 2006, 16:28:28)
[GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-53)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print “hello, world!”
hello, world!
The interpreter
Try printing various things
Leave off the quotation marks.
Print numbers, letters and combinations.
Print two things, with a comma between.
Enter a mathematical formula.
Leave off the word “print”.
The interpreter allows you to try things out
interactively and quickly.
Use the interpreter to test syntax, or to try
commands that you’re not sure will work when you
run your program.
Your first program
In your terminal, Ctrl-D out of python.
Type “pwd” to find your current working directory.
Open TextWrangler.
Create a file containing one line:
print “hello, world!”
Be sure that you end the line with a carriage return.
Save the file as “hello.py” in your current working directory.
In your terminal, type “python hello.py”
> python hello.py
hello, world!
Notice that, once you
save the file with “.py”
as the extension,
WordWrangler
automatically colors
the text according to
the syntax.
Objects and types
• We use the term object to refer to any entity in a python program.
• Every object has an associated type, which determines the properties of the
object.
• Python defines six types of built-in objects:
Number 10
String “hello”
List [1, 17, 44]
Tuple (4, 5)
Dictionary {‘food’ : ‘something you eat’,
‘lobster’ : ‘an edible, undersea arthropod’}
Files
• Each type of object has its own properties, which we will learn about in the
next several weeks.
• It is also possible to define your own types, comprised of combinations of
the six base types.
Literals and variables
•A variable is simply another name for an object.
•For example, we can assign the name “pi” to the
object 3.14159, as follows:
>>> pi = 3.14159
>>> print pi
3.14159
•When we write out the object directly, it is a literal,
as opposed to when we refer to it by its variable
name.
The “import” command
•Many python functions are only available via
“packages” that must be imported.
>>> print log(10)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'log' is not defined
>>> import math
>>> print math.log(10)
2.30258509299
The command line
• To get information into a program, we will typically use the
command line.
• The command line is the text you enter after the word
“python” when you run a program.
import sys
print "hello, world!"
print sys.argv[0]
print sys.argv[1]
• The zeroth argument is the name of the program file.
• Arguments larger than zero are subsequent elements of the
command line.
Sample problem #1
•Write a program called “print-two-args.py” that
reads the first two command line arguments after
the program name, stores their values as variables,
and then prints them on the same line with a colon
between.
> python print-two-args.py hello world
hello : world
Solution #1
import sys
arg1 = sys.argv[1]
arg2 = sys.argv[2]
print arg1, ":", arg2
Sample problem #2
•Write a program called “add-two-args.py” that
reads the first two command line arguments after
the program name, stores their values as variables,
and then prints their sum.
•Hint: To read an argument as a number, use the
syntax “arg1 = float(sys.argv[1])”
> python add-two-args.py 1 2
3.0
Solution #2
import sys
arg1 = float(sys.argv[1])
arg2 = float(sys.argv[2])
print arg1 + arg2

Contenu connexe

Tendances

Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)Matt Harrison
 
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and ModulesRaginiJain21
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksEueung Mulyana
 
Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert QA TrainingHub
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-pythonAakashdata
 
Introduction Jupyter Notebook
Introduction Jupyter NotebookIntroduction Jupyter Notebook
Introduction Jupyter Notebookthirumurugan133
 
java copy file program
java copy file programjava copy file program
java copy file programGlen Pais
 
Learn PYTHON at ASIT
Learn PYTHON at ASITLearn PYTHON at ASIT
Learn PYTHON at ASITASIT
 
Demystifying how imports work in Python
Demystifying how imports work in PythonDemystifying how imports work in Python
Demystifying how imports work in Pythonprodicus
 
Groovy
GroovyGroovy
Groovyatonse
 
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...Edureka!
 
Getting started with Linux and Python by Caffe
Getting started with Linux and Python by CaffeGetting started with Linux and Python by Caffe
Getting started with Linux and Python by CaffeLihang Li
 
The Ring programming language version 1.5.1 book - Part 38 of 180
The Ring programming language version 1.5.1 book - Part 38 of 180The Ring programming language version 1.5.1 book - Part 38 of 180
The Ring programming language version 1.5.1 book - Part 38 of 180Mahmoud Samir Fayed
 
Distributed Storage with IPFS and Python!
Distributed Storage with IPFS and Python!Distributed Storage with IPFS and Python!
Distributed Storage with IPFS and Python!Abhinav Srivastava
 

Tendances (20)

Why Python (for Statisticians)
Why Python (for Statisticians)Why Python (for Statisticians)
Why Python (for Statisticians)
 
Python Libraries and Modules
Python Libraries and ModulesPython Libraries and Modules
Python Libraries and Modules
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
File io
File io File io
File io
 
Python final ppt
Python final pptPython final ppt
Python final ppt
 
Introduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter NotebooksIntroduction to IPython & Jupyter Notebooks
Introduction to IPython & Jupyter Notebooks
 
Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert Best Python Online Training with Live Project by Expert
Best Python Online Training with Live Project by Expert
 
Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
Introduction Jupyter Notebook
Introduction Jupyter NotebookIntroduction Jupyter Notebook
Introduction Jupyter Notebook
 
Python Intro
Python IntroPython Intro
Python Intro
 
java copy file program
java copy file programjava copy file program
java copy file program
 
Learn PYTHON at ASIT
Learn PYTHON at ASITLearn PYTHON at ASIT
Learn PYTHON at ASIT
 
working with files
working with filesworking with files
working with files
 
Demystifying how imports work in Python
Demystifying how imports work in PythonDemystifying how imports work in Python
Demystifying how imports work in Python
 
Groovy
GroovyGroovy
Groovy
 
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
Advanced Python Tutorial | Learn Advanced Python Concepts | Python Programmin...
 
Getting started with Linux and Python by Caffe
Getting started with Linux and Python by CaffeGetting started with Linux and Python by Caffe
Getting started with Linux and Python by Caffe
 
The Ring programming language version 1.5.1 book - Part 38 of 180
The Ring programming language version 1.5.1 book - Part 38 of 180The Ring programming language version 1.5.1 book - Part 38 of 180
The Ring programming language version 1.5.1 book - Part 38 of 180
 
Distributed Storage with IPFS and Python!
Distributed Storage with IPFS and Python!Distributed Storage with IPFS and Python!
Distributed Storage with IPFS and Python!
 
Python ppt
Python pptPython ppt
Python ppt
 

En vedette

Game playing (tic tac-toe), andor graph
Game playing (tic tac-toe), andor graphGame playing (tic tac-toe), andor graph
Game playing (tic tac-toe), andor graphSyed Zaid Irshad
 
Cube permutation multistage
Cube permutation multistageCube permutation multistage
Cube permutation multistageSyed Zaid Irshad
 
Interconnection mechanisms
Interconnection mechanismsInterconnection mechanisms
Interconnection mechanismsSyed Zaid Irshad
 
Fotografía de página completa
Fotografía de página completaFotografía de página completa
Fotografía de página completaAda Luz Olivares
 
Presentation #1
Presentation #1Presentation #1
Presentation #1KMOlson12
 
Ilirika Jugoistocna Evropa
Ilirika Jugoistocna EvropaIlirika Jugoistocna Evropa
Ilirika Jugoistocna Evropaguest29c407b0
 
Proyecto final curso leer e investigar en la era digital
Proyecto final curso leer e investigar en la era digitalProyecto final curso leer e investigar en la era digital
Proyecto final curso leer e investigar en la era digitalCristina Marchante
 
Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...
Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...
Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...Laura Cavallaro
 
Reduced instruction set computers
Reduced instruction set computersReduced instruction set computers
Reduced instruction set computersSyed Zaid Irshad
 

En vedette (20)

Game playing (tic tac-toe), andor graph
Game playing (tic tac-toe), andor graphGame playing (tic tac-toe), andor graph
Game playing (tic tac-toe), andor graph
 
Cube permutation multistage
Cube permutation multistageCube permutation multistage
Cube permutation multistage
 
Interconnection mechanisms
Interconnection mechanismsInterconnection mechanisms
Interconnection mechanisms
 
IT Infrastructure
IT InfrastructureIT Infrastructure
IT Infrastructure
 
Fotografía de página completa
Fotografía de página completaFotografía de página completa
Fotografía de página completa
 
Presentation #1
Presentation #1Presentation #1
Presentation #1
 
Norian SRS Rotary Mix
Norian SRS Rotary MixNorian SRS Rotary Mix
Norian SRS Rotary Mix
 
Ilirika Jugoistocna Evropa
Ilirika Jugoistocna EvropaIlirika Jugoistocna Evropa
Ilirika Jugoistocna Evropa
 
Bagini Glacier Trek
Bagini Glacier TrekBagini Glacier Trek
Bagini Glacier Trek
 
24. Kecamatan pagindar
24. Kecamatan pagindar24. Kecamatan pagindar
24. Kecamatan pagindar
 
Everest Base Camp
Everest Base CampEverest Base Camp
Everest Base Camp
 
Nandanvan-Tapovan
Nandanvan-TapovanNandanvan-Tapovan
Nandanvan-Tapovan
 
Proyecto final curso leer e investigar en la era digital
Proyecto final curso leer e investigar en la era digitalProyecto final curso leer e investigar en la era digital
Proyecto final curso leer e investigar en la era digital
 
Systolic array
Systolic arraySystolic array
Systolic array
 
Multicore computers
Multicore computersMulticore computers
Multicore computers
 
Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...
Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...
Mobile Content - Contenuti digitali: mercato, scenari e opportunità dal Canal...
 
Reduced instruction set computers
Reduced instruction set computersReduced instruction set computers
Reduced instruction set computers
 
Business plan (2)
Business plan (2)Business plan (2)
Business plan (2)
 
Data model
Data modelData model
Data model
 
Butterfly network
Butterfly networkButterfly network
Butterfly network
 

Similaire à Introduction to python

1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt1B-Introduction_to_python.ppt
1B-Introduction_to_python.pptAmritMarwaha1
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughgabriellekuruvilla
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptxArpittripathi45
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdfsamiwaris2
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdfgmadhu8
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPTShivam Gupta
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programmingChetan Giridhar
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security ProfessionalsAditya Shankar
 
Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3FabMinds
 
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
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unitmichaelaaron25322
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1Elaf A.Saeed
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of pythonBijuAugustian
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python ProgrammingDozie Agbo
 

Similaire à Introduction to python (20)

1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt
 
Python and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthroughPython and Pytorch tutorial and walkthrough
Python and Pytorch tutorial and walkthrough
 
python presntation 2.pptx
python presntation 2.pptxpython presntation 2.pptx
python presntation 2.pptx
 
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
 
python into.pptx
python into.pptxpython into.pptx
python into.pptx
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Python
PythonPython
Python
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
python-ppt.ppt
python-ppt.pptpython-ppt.ppt
python-ppt.ppt
 
Tutorial on-python-programming
Tutorial on-python-programmingTutorial on-python-programming
Tutorial on-python-programming
 
Python for Security Professionals
Python for Security ProfessionalsPython for Security Professionals
Python for Security Professionals
 
Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3
 
Python fundamentals
Python fundamentalsPython fundamentals
Python fundamentals
 
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
 
Python programming language introduction unit
Python programming language introduction unitPython programming language introduction unit
Python programming language introduction unit
 
05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Python basics_ part1
Python basics_ part1Python basics_ part1
Python basics_ part1
 
Fundamentals of python
Fundamentals of pythonFundamentals of python
Fundamentals of python
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
 

Plus de Syed Zaid Irshad

Plus de Syed Zaid Irshad (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
C Language
C LanguageC Language
C Language
 
Flowchart
FlowchartFlowchart
Flowchart
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Data Communication
Data CommunicationData Communication
Data Communication
 
Information Networks
Information NetworksInformation Networks
Information Networks
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Dernier

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 

Dernier (20)

Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 

Introduction to python

  • 2. Why Python? • Python is • easy to learn, • relatively fast, • object-oriented, • strongly typed, • widely used, and • portable. • C is much faster but much harder to use. • Java is about as fast and slightly harder to use. • Perl is slower, is as easy to use, but is not strongly typed.
  • 3. Getting started on the Mac • Start a terminal session. • Type “python” • This should start the Python interpreter > python Python 2.4.2 (#2, Apr 10 2006, 16:28:28) [GCC 3.2.3 20030502 (Red Hat Linux 3.2.3-53)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print “hello, world!” hello, world!
  • 4. The interpreter Try printing various things Leave off the quotation marks. Print numbers, letters and combinations. Print two things, with a comma between. Enter a mathematical formula. Leave off the word “print”. The interpreter allows you to try things out interactively and quickly. Use the interpreter to test syntax, or to try commands that you’re not sure will work when you run your program.
  • 5. Your first program In your terminal, Ctrl-D out of python. Type “pwd” to find your current working directory. Open TextWrangler. Create a file containing one line: print “hello, world!” Be sure that you end the line with a carriage return. Save the file as “hello.py” in your current working directory. In your terminal, type “python hello.py” > python hello.py hello, world! Notice that, once you save the file with “.py” as the extension, WordWrangler automatically colors the text according to the syntax.
  • 6. Objects and types • We use the term object to refer to any entity in a python program. • Every object has an associated type, which determines the properties of the object. • Python defines six types of built-in objects: Number 10 String “hello” List [1, 17, 44] Tuple (4, 5) Dictionary {‘food’ : ‘something you eat’, ‘lobster’ : ‘an edible, undersea arthropod’} Files • Each type of object has its own properties, which we will learn about in the next several weeks. • It is also possible to define your own types, comprised of combinations of the six base types.
  • 7. Literals and variables •A variable is simply another name for an object. •For example, we can assign the name “pi” to the object 3.14159, as follows: >>> pi = 3.14159 >>> print pi 3.14159 •When we write out the object directly, it is a literal, as opposed to when we refer to it by its variable name.
  • 8. The “import” command •Many python functions are only available via “packages” that must be imported. >>> print log(10) Traceback (most recent call last): File "<stdin>", line 1, in ? NameError: name 'log' is not defined >>> import math >>> print math.log(10) 2.30258509299
  • 9. The command line • To get information into a program, we will typically use the command line. • The command line is the text you enter after the word “python” when you run a program. import sys print "hello, world!" print sys.argv[0] print sys.argv[1] • The zeroth argument is the name of the program file. • Arguments larger than zero are subsequent elements of the command line.
  • 10. Sample problem #1 •Write a program called “print-two-args.py” that reads the first two command line arguments after the program name, stores their values as variables, and then prints them on the same line with a colon between. > python print-two-args.py hello world hello : world
  • 11. Solution #1 import sys arg1 = sys.argv[1] arg2 = sys.argv[2] print arg1, ":", arg2
  • 12. Sample problem #2 •Write a program called “add-two-args.py” that reads the first two command line arguments after the program name, stores their values as variables, and then prints their sum. •Hint: To read an argument as a number, use the syntax “arg1 = float(sys.argv[1])” > python add-two-args.py 1 2 3.0
  • 13. Solution #2 import sys arg1 = float(sys.argv[1]) arg2 = float(sys.argv[2]) print arg1 + arg2