Size: 633
Comment:
|
Size: 2799
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
The metabolic modelling we will be using, {{ScrumPy}}}, is written in {{{Python}}}. {{{Python}}} is a high-level, object-oriented, interpreted programming language, it has a lange standard library, and supports multiple programming paradigms. It is also syntactically clear and easy to learn. This is a very brief introduction to some of the basic features of the language, for a more complete introduction to the topic, see Lutz & Ascher, "Learning Python" O'Reilly Media inc. (Edition 2 or greater). |
The metabolic modelling we will be using, {{{ScrumPy}}}, is written in {{{Python}}}. {{{Python}}} is a high-level, object-oriented, interpreted programming language, it has a large standard library, and supports multiple programming paradigms. It is also syntactically clear and easy to learn. This is a very brief introduction to some of the basic features of the language, for a more complete introduction to the topic, see Lutz & Ascher, "Learning Python" O'Reilly Media inc. (Edition 2 or greater). A good source of {{{Python}}} documentation can be found [[http://docs.python.org/ | here]]. |
Line 10: | Line 7: |
We will be using {{{Python}}} from the {{{ScrumPy}}} environment. | We will be using {{{Python}}} from the {{{ScrumPy}}} environment. To start a new {{{ScrumPy}}} session open a terminal and type "{{{ScrumPy}}}": {{{ user@machine:~$ ScrumPy & }}} which will launch the {{{ScrumPy}}} window. == Data types == === Numbers === The numerical types we will be dealing with are integers, {{{int}}}, and floating-point numbers {{{float}}}. Integers are written as a sequence of digits. Floats are written as digits with a decimal point in the sequence, and an optional exponent ({{{e}}} or {{{E}}}). {{{#!python >>> n_int = 135 >>> n_int 135 >>> n_float = 10e-10 >>> n_float 1.0000e-9 }}} The type of a given data object can be checked using the built-in function {{{type()}}}. {{{#! >>> type(n_int) <type 'int'> >>>type(n_float) <type 'float'> }}} Floats and integers can be interconverted using the constructors {{{int()}}} or {{{float()}}}. {{{#! >>> n_int2float=float(n_int) >>> n_int2float 135.0 >>> type(n_int2float) <type 'float'> #n_int is still an integer }}} The common matematical operators ({{{+,-,/,*}}}) work as expected, note that {{{x**y}}} means ''x''^y^. === Boolean === Booleans are a subtype of integers. A boolean type is either {{{True}}} or {{{False}}}, and can be very useful when writing conditional statements, i.e. {{{if something is True, do something}}}. Also, the integer {{{0}}} is {{{False}}}. {{{#! python >>> val=True >>> if val: print 'val is true' val is true >>> val=False >>> if val: print 'val is true' >>> }}} === Strings === Strings are collections of characters. Characters in a string can be accessed by ''indexing'', and ''membership'' of a subset of characters in a string can be evaluated. {{{#! python >>> s_1 = 'another string' #create string >>> s_2 = s_1[:7] #create new string of characters 0 to 6 in s_1 >>> s_2 'another' >>> if s_2 in s_1: #check for membership of s_2 in s_1 print 'true' true }}} == Lists and tuples == == Dictionaries == == Modules == == Objects == == Loops and conditionals == |
Introduction to Python
The metabolic modelling we will be using, ScrumPy, is written in Python. Python is a high-level, object-oriented, interpreted programming language, it has a large standard library, and supports multiple programming paradigms. It is also syntactically clear and easy to learn. This is a very brief introduction to some of the basic features of the language, for a more complete introduction to the topic, see Lutz & Ascher, "Learning Python" O'Reilly Media inc. (Edition 2 or greater). A good source of Python documentation can be found here.
Getting started
We will be using Python from the ScrumPy environment. To start a new ScrumPy session open a terminal and type "ScrumPy":
user@machine:~$ ScrumPy &
which will launch the ScrumPy window.
Data types
Numbers
The numerical types we will be dealing with are integers, int, and floating-point numbers float. Integers are written as a sequence of digits. Floats are written as digits with a decimal point in the sequence, and an optional exponent (e or E).
The type of a given data object can be checked using the built-in function type().
>>> type(n_int) <type 'int'> >>>type(n_float) <type 'float'>
Floats and integers can be interconverted using the constructors int() or float().
>>> n_int2float=float(n_int) >>> n_int2float 135.0 >>> type(n_int2float) <type 'float'> #n_int is still an integer
The common matematical operators (+,-,/,*) work as expected, note that x**y means xy.
Boolean
Booleans are a subtype of integers. A boolean type is either True or False, and can be very useful when writing conditional statements, i.e. if something is True, do something. Also, the integer 0 is False.
>>> val=True >>> if val: print 'val is true' val is true >>> val=False >>> if val: print 'val is true' >>>
Strings
Strings are collections of characters. Characters in a string can be accessed by indexing, and membership of a subset of characters in a string can be evaluated.
>>> s_1 = 'another string' #create string >>> s_2 = s_1[:7] #create new string of characters 0 to 6 in s_1 >>> s_2 'another' >>> if s_2 in s_1: #check for membership of s_2 in s_1 print 'true' true
Lists and tuples
Dictionaries
Modules
Objects