pythonprimer

pythonprimer - a39 a38 3 The python Programming Language...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: a39 a38 3 The python Programming Language 3.1 Introduction AIM: teach the essentials of modelling under time constraints Scientific Computing Process: Model Reality Algorithm Program Many choices at each stage A thorough understanding of all stages is necessary, but we are limited in time choose an appropriate computer language 3.2 Why python for this course? python is an interpreted , interactive, object-oriented programming language. python ideal for teaching: 31 + interpreted makes for ease of use (no compiling, linking etc.) + small, compact language easy to learn + freely available for many types of machines (Linux/Unix, Microsoft, Mac)- not as efficient as compiled languages (C, FORTRAN) + Benefit beyond the course: general batch based text processing python widely used in bioinformatics 3.3 Data Types and Variables AIM: we need to store the data we operate on. Various data types required. Simple data types: atomic data types used to store a single value. integer : positive and negative whole numbers, limited in range (32 bits: [ 2147483648 . . . 2147483647 ] ) long integer : Arbitrary precision integer floating point : real numbers (64 bit IEEE format). 32 complex : complex numbers Listing 6: Simple data types a i n t = 1000; b i n t = 200 c r e a l = 42.0; d r e a l = 70.5 ecomplex= c r e a l +0.5 j ; fcomplex=ecomplex * (30.0+6 j ) p r i n t a i n t , b i n t , a i n t + b i n t , a i n t b i n t p r i n t c real , dreal , c r e a l * dreal , c r e a l / d r e a l p r i n t ecomplex , fcomplex 1000 200 800 1200 42.0 70.5 2961.0 0.595744680851 ( 42+0.5 j ) ( 1263 237 j ) Sequence data types: ordered set of variables indexed by natural numbers. character or string : sequence of characters list : mutable sequence of variables tuple : immutable sequence of variables 33 Listing 7: Sequence data types a s t r = chem 507 ; b s t r = " i s great fun " c l s t = [ 1 , 2 , 4 . 0 , a ] ; d l s t =[ h e l l o , c l s t ] e t u p l e = ( 5 . 0 , 6 . 0 , 7 . 0 ) ; f t u p l e =( as tr , c l s t , e t u p l e ) p r i n t as tr , b s t r p r i n t c l s t p r i n t d l s t p r i n t etuple , " \ n " , f t u p l e p r i n t d l s t [ 0 ] , f t u p l e [ 0 ]...
View Full Document

Page1 / 14

pythonprimer - a39 a38 3 The python Programming Language...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online