320 likes | 543 Views
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
E N D
Introduction to Python BCHB5242010Lecture 1 BCHB524 - 2010 - Edwards
Outline • Why Python? • Installation • Basic Data Types • Expressions • Variables • Functions • Control Flow BCHB524 - 2010 - Edwards
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? • Good with • Strings • Files and Formats • Web and Databases • Objects and Concepts • BioPython • www.biopython.org BCHB524 - 2010 - Edwards
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 • 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) • 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 • Choose "Python Shell (IDLE)" from Start >> BCHB524 BCHB524 - 2010 - Edwards
Basic Data Types • Integer • Float (real numbers) • String Also: • Boolean • None • Tuples BCHB524 - 2010 - Edwards
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 BCHB524 - 2010 - Edwards
Basic Data Types: Strings BCHB524 - 2010 - Edwards
Conversions BCHB524 - 2010 - Edwards
Expressions BCHB524 - 2010 - Edwards
Tests BCHB524 - 2010 - Edwards
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 • Execute a small (predefined) task BCHB524 - 2010 - Edwards
Using Methods • Execute a small task with a specific object BCHB524 - 2010 - Edwards
Defining New Functions • Describe how to execute a small task BCHB524 - 2010 - Edwards
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 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 • Conditional execution • Note use of indentation to define a block! BCHB524 - 2010 - Edwards
First program BCHB524 - 2010 - Edwards
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 0 BCHB524 - 2010 - Edwards
Homework 0 BCHB524 - 2010 - Edwards