Introduction to python
Download
1 / 26

Introduction to Python - PowerPoint PPT Presentation


  • 111 Views
  • Uploaded on

Introduction to Python. BCHB524 2010 Lecture 1. Outline. Why Python? Installation Basic Data Types Expressions Variables Functions Control Flow. Why Python?. Free Portable Object-oriented Clean syntax Dynamic Scientific, Commercial Support libraries Extensible Interactive

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Introduction to Python' - truman


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Introduction to python

Introduction to Python

BCHB5242010Lecture 1

BCHB524 - 2010 - Edwards


Outline
Outline

  • Why Python?

  • Installation

  • Basic Data Types

  • Expressions

  • Variables

  • Functions

  • Control Flow

BCHB524 - 2010 - Edwards


Why python
Why Python?

  • Free

  • Portable

  • Object-oriented

  • Clean syntax

  • Dynamic

  • Scientific, Commercial

  • Support libraries

  • Extensible

  • Interactive

  • Modern

BCHB524 - 2010 - Edwards

http://xkcd.com/353/


Why python for bioinformatics
Why Python for Bioinformatics?

  • Good with

    • Strings

    • Files and Formats

    • Web and Databases

    • Objects and Concepts

  • BioPython

    • www.biopython.org

BCHB524 - 2010 - Edwards


Python versions
Python Versions

  • Python 2.6.x

    • Transition (to 3.x) version, warns about things that'll break in 3.x.

    • Compatible with most "extra" Python modules (incl. BioPython)

  • Python 2.7.x

    • Transition (to 3.x) version, warns about things that'll break in 3.x.

    • Last 2.x version, some 3.x features ported back.

    • Some extra Python modules not yet available (incl. BioPython)

  • Python 3.x

    • Significant break from Python 2.x, especially strings (very important!). Syntax differences!

    • Relatively few extra modules have been ported, so far.

BCHB524 - 2010 - Edwards


Installation
Installation

  • Python Homepage

    • www.python.org

  • >> Download >> Releases >> 2.6.6 >> Select Operating System

    • We’ll use version 2.6.6 on Windows

    • OS X & Linux versions also readily available.

  • Integrated development environment – IDLE

BCHB524 - 2010 - Edwards


Installation nrb w402
Installation (NRB W402)

  • Python and the other tools we'll use are preinstalled.

  • Folder C:\BCHB524 contains all the software

    • Start menu has BCHB524 program group

  • Download installer from course web-site data-directory (Windows)

BCHB524 - 2010 - Edwards


Idle screen shot
IDLE Screen-Shot

  • Choose "Python Shell (IDLE)" from Start >> BCHB524

BCHB524 - 2010 - Edwards


Basic data types
Basic Data Types

  • Integer

  • Float (real numbers)

  • String

    Also:

  • Boolean

  • None

  • Tuples

BCHB524 - 2010 - Edwards


Basic data types integers
Basic Data Types: Integers

>>> 3

3

>>> 3*4

12

>>> 3/4

0

>>> abs(-10)

10

>>> 3%4

3

>>> 2**32

4294967296L

>>> 2**64

18446744073709551616L

>>> 2**128

340282366920938463463374607431768211456L

>>> print 2**128

340282366920938463463374607431768211456

BCHB524 - 2010 - Edwards


Basic data types floats
Basic Data Types: Floats

BCHB524 - 2010 - Edwards


Basic data types strings
Basic Data Types: Strings

BCHB524 - 2010 - Edwards


Conversions
Conversions

BCHB524 - 2010 - Edwards


Expressions
Expressions

BCHB524 - 2010 - Edwards


Tests
Tests

BCHB524 - 2010 - Edwards


Variables
Variables

  • Store values for later use>>> seq = 'gcatgacgttattacgactctgtgtggcgtctgctggg‘>>> len(seq)

    38

    >>> seq = seq * 3

    >>> len(seq)

    114

    >>> met = ('A','T','G')

    >>> print met

    ('A', 'T', 'G')

BCHB524 - 2010 - Edwards


Using functions
Using Functions

  • Execute a small (predefined) task

BCHB524 - 2010 - Edwards


Using methods
Using Methods

  • Execute a small task with a specific object

BCHB524 - 2010 - Edwards


Defining new functions
Defining New Functions

  • Describe how to execute a small task

BCHB524 - 2010 - Edwards


Too much typing
Too much typing!

  • Place statements in a Python (.py) file.

  • Execute in IDLE using F5

  • Must use print to see output

BCHB524 - 2010 - Edwards


Too much typing1
Too much typing!

  • Place statements in a Python (.py) file.

  • Execute in IDLE using F5

  • Must use print to see output

BCHB524 - 2010 - Edwards


Control flow if statements
Control Flow: If Statements

  • Conditional execution

  • Note use of indentation to define a block!

BCHB524 - 2010 - Edwards


First program
First program

BCHB524 - 2010 - Edwards


Homework 0
Homework 0

  • Due tomorrow, Sep 2nd, 12 noon

  • Complete two python programs using only the material in this lecture

  • Program shells provided

    • Make sure you test with multiple "inputs"

  • Run using IDLE (F5)

BCHB524 - 2010 - Edwards


Homework 01
Homework 0

BCHB524 - 2010 - Edwards


Homework 02
Homework 0

BCHB524 - 2010 - Edwards


ad