1 / 26

Introduction to Python

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

truman
Download Presentation

Introduction to Python

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Python BCHB5242010Lecture 1 BCHB524 - 2010 - Edwards

  2. Outline • Why Python? • Installation • Basic Data Types • Expressions • Variables • Functions • Control Flow BCHB524 - 2010 - Edwards

  3. Why Python? • Free • Portable • Object-oriented • Clean syntax • Dynamic • Scientific, Commercial • Support libraries • Extensible • Interactive • Modern BCHB524 - 2010 - Edwards http://xkcd.com/353/

  4. Why Python for Bioinformatics? • Good with • Strings • Files and Formats • Web and Databases • Objects and Concepts • BioPython • www.biopython.org BCHB524 - 2010 - Edwards

  5. 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

  6. 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

  7. 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

  8. IDLE Screen-Shot • Choose "Python Shell (IDLE)" from Start >> BCHB524 BCHB524 - 2010 - Edwards

  9. Basic Data Types • Integer • Float (real numbers) • String Also: • Boolean • None • Tuples BCHB524 - 2010 - Edwards

  10. 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

  11. Basic Data Types: Floats BCHB524 - 2010 - Edwards

  12. Basic Data Types: Strings BCHB524 - 2010 - Edwards

  13. Conversions BCHB524 - 2010 - Edwards

  14. Expressions BCHB524 - 2010 - Edwards

  15. Tests BCHB524 - 2010 - Edwards

  16. 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

  17. Using Functions • Execute a small (predefined) task BCHB524 - 2010 - Edwards

  18. Using Methods • Execute a small task with a specific object BCHB524 - 2010 - Edwards

  19. Defining New Functions • Describe how to execute a small task BCHB524 - 2010 - Edwards

  20. Too much typing! • Place statements in a Python (.py) file. • Execute in IDLE using F5 • Must use print to see output BCHB524 - 2010 - Edwards

  21. Too much typing! • Place statements in a Python (.py) file. • Execute in IDLE using F5 • Must use print to see output BCHB524 - 2010 - Edwards

  22. Control Flow: If Statements • Conditional execution • Note use of indentation to define a block! BCHB524 - 2010 - Edwards

  23. First program BCHB524 - 2010 - Edwards

  24. 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

  25. Homework 0 BCHB524 - 2010 - Edwards

  26. Homework 0 BCHB524 - 2010 - Edwards

More Related