Python - The KickStart

Embed Size (px)

Citation preview

  • 8/14/2019 Python - The KickStart

    1/19

    Which of these languages doyou know?

    C or C++

    Java

    Perl

    Scheme

    Fortran Python

    Matlab

    1

  • 8/14/2019 Python - The KickStart

    2/19

    History of Python

    Created in 1990 by Guido van Rossum Named ater Monty Python

    First !ublic release in 1991

    com!" lan#"!ython ounded in 199$ %!en source rom the start

    &

  • 8/14/2019 Python - The KickStart

    3/19

    INTRODUCTION ' !ro#rammin# lan#ua#e (ith stron#

    similarities to P)R* but (ith !o(erul ty!in#

    and ob,ect oriented eatures"

    Commonly used or !roducin# -.M* contenton (ebsites" Great or te/t iles"

    seul builtin ty!es 2lists dictionaries3"

    Clean synta/ !o(erul e/tensions"

    4

  • 8/14/2019 Python - The KickStart

    4/19

    Why Python? Natural *an#ua#e .ool5it )ase o use6 inter!reter '7 Processin#8 Symbolic

    Pythons builtin dataty!es or strin#s listsand more"

    Java or C++ re:uire the use o s!ecial classesor this"

    '7 Processin#8 Statistical Python has stron# numeric !rocessin#ca!abilities8 matri/ o!erations etc"

    Suitable or !robability and machine learnin#code

    $

  • 8/14/2019 Python - The KickStart

    5/19

    Python Overview

    Pro#rams are com!osed o modules

    Modules contain statements Statements contain e/!ressions

    )/!ressions create and !rocess ob,ects

    ;

  • 8/14/2019 Python - The KickStart

    6/19

    Hello World %!en a terminal (indo( and ty!e

    7 on >indo(s o!en a Python 7?) li@e 7?*)

    't the !rom!t ty!e Ahello (orldB

    Dhello (orldBD

    Dhello (orldBD

    E

  • 8/14/2019 Python - The KickStart

    7/19

    The Python Interpreter

    Python is an

    inter!reted lan#ua#e

    .he inter!reter

    !rovides aninteractive

    environment to !lay

    (ith the lan#ua#e

    Results o e/!ressions

    are !rinted on the

    screen

    4 +

    10

    4 1;

    .rue

    D!rint meD

    D!rint meD

    !rint D!rint meD!rint me

  • 8/14/2019 Python - The KickStart

    8/19

    The print Statement

    )lements se!arated

    by commas !rint

    (ith a s!ace

    bet(een them

    ' comma at the

    end o the

    statement 2!rint

    Ahello3 (ill not

    !rint a ne(line

    character

    !rint DhelloD

    hello

    !rint DhelloD DthereDhello there

    H

  • 8/14/2019 Python - The KickStart

    9/19

    Documentation

    .he AI starts a line comment

    Dthis (ill !rintD

    Dthis (ill !rintD

    IDthis (ill notD

    9

  • 8/14/2019 Python - The KickStart

    10/19

    Look at a sample of code

    x = 34 - 23 # A comment.

    y = Hello # Another one.

    z = 3.45

    ifz == 3.45 ory == Hello:

    x = x + 1

    y = y + Worl # !trin" conct.

    $rintx$rinty

    10

  • 8/14/2019 Python - The KickStart

    11/19

    !no"#h to Understand the Code 'ssi#nment uses and com!arison uses " For numbers +KL are as e/!ected"

    S!ecial use o + or strin# concatenation" S!ecial use o or strin# ormattin#"

    *o#ical o!erators are (ords 2n% or% not3not symbols (&&, ||, !).

    .he basic !rintin# command is

    ariable ty!es dont need to be declared" Python i#ures out the variable ty!es on its o(n"

    11

  • 8/14/2019 Python - The KickStart

    12/19

    Variales

    're not declared ,ust assi#ned .he variable is created the irst time you assi#n

    it a value 're reerences to ob,ects .y!e inormation is (ith the ob,ect not the

    reerence

    )verythin# in Python is an ob,ect

    1&

  • 8/14/2019 Python - The KickStart

    13/19

    !verything is an o"ect

    )verythin# means

    everythin# includin#

    unctions and classes

    2more on this laterB3

    ?ata ty!e is a !ro!erty

    o the ob,ect and noto the variable

    /

    /

    / DhelloD

    /

    DhelloD

    14

  • 8/14/2019 Python - The KickStart

    14/19

    $OD!% IN P&THON

    Python has t(o basic modes8 normal and

    interactive" .he normal mode is the mode

    (here the scri!ted and inished "!y iles are

    run in the Python inter!reter" 7nteractivemode is a command line shell (hich #ives

    immediate eedbac@ or each statement

    (hile runnin# !reviously ed statements in

    active memory" 's ne( lines are ed into the

    inter!reter the ed !ro#ram is evaluated

    both in !art and in (hole"

    1$

  • 8/14/2019 Python - The KickStart

    15/19

    .o start interactive mode sim!ly ty!e

    !ython (ithout any ar#uments"

    .he is PythonDs (ay o tellin# you that

    you are in interactive mode" 7n interactive

    mode (hat you ty!e is immediately run".ry ty!in#1+1 in" Python (ill res!ond

    (ith &" 7nteractive mode allo(s you to test

    out and see (hat Python (ill do" 7 you

    ever eel the need to !lay (ith ne( Pythonstatements #o into interactive mode and

    try them out"

    1;

  • 8/14/2019 Python - The KickStart

    16/191E

    ' sam!le interactive session is Q

  • 8/14/2019 Python - The KickStart

    17/191

  • 8/14/2019 Python - The KickStart

    18/191H

  • 8/14/2019 Python - The KickStart

    19/19

    $a'or Uses of Python

    System tilities

    G7s 2.@inter #t@ t >indo(s3 7nternet Scri!tin#

    )mbedded Scri!tin#

    ?atabase Pro#rammin# 'rtiicial 7ntelli#ence

    7ma#e Processin#

    19