Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet33/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   29   30   31   32   33   34   35   36   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Simple data types

As with other computer languages, Python has various simple, inbuilt types of data. These

are  Boolean  values,  integers,  floating  point  numbers,  complex  numbers,  text  strings  and

the null object.



Boolean  values  represent  truth  or  falsehood,  as  used  in  logic  operations.  Not

surprisingly,  there  are  only  two  values,  and  in  Python  they  are  called  True  and  False.

3

Example usage:



a = True

b = False



Integers represent whole numbers, as you would use when counting items, and can be

positive or negative. In Python 2 there are two types of integers, plain integers and long

integers.

4

 Plain  integers  have  a  maximum  size  dependent  on  the  specific  Python



implementation  you  are  using.  On  a  typical  computer  the  largest  plain  integer  would  be

2

31



−1  or  2

63

−1  (for  32  bit  and  64  bit  respectively).  There  is  no  limit  on  long  integers



except  for  what  can  fit  into  available  memory.  In  Python  3  there  is  only  one  type  of

integer,  the  long  integer.  Unless  you  are  doing  something  unusual,  there  is  no  point

worrying  about  this  distinction  or  the  difference  between  the  two  types,  and  in  most

situations in Python 2 the plain integers will suffice. Example usage:

x = -7

y = 123


Floating  point  numbers  (in  mathematics  the  real  numbers),  which  are  written  with

decimal  points  or  exponential  notation,  are  not  always  represented  exactly,  since  a

computer has only a finite amount of memory. This introduces issues to do with numerical

errors,  and  potential  instability  of  numerical  algorithms.  However,  such  issues  are




common to all computer languages. Example usage:

z = 123.45

There  is  also  an  inbuilt  data  type  to  represent  complex  numbers  which  you  would

normally write in the form ‘a+bi’ (mathematical notation) or ‘a+bj’ (engineering notation).

Although  complex  numbers  occur  quite  naturally  in  mathematics,  science  and

engineering,  relatively  few  Python  programs  use  them.  The  Python  syntax  follows  the

engineering  style  and  the  real  and  imaginary  parts  can  themselves  be  integer  or  floating

point:


x = 3+4j

y = 1.2-5.8j



Strings represent text, i.e. strings of characters. They can be delimited by single quotes

(’) or double quotes (”), but you have to use the same delimiter at both ends. Unlike some

programming  languages,  such  as  Perl,  there  is  no  practical  difference  between  the  two

types  of  quote,  although  using  one  type  does  allow  the  other  type  to  appear  inside  the

string as a regular character. Example usage:

r1 = 'Ala'

r2 = "Arg"

text = "It's a line with an apostrophe"

Python  also  allows  multi-line  strings,  which  start  and  end  either  with  triple  single

quotes (”’) or triple double quotes (”””). Example usage:

text = """Python also allows multi-line strings, which

start and end with a triple single quote or a triple

double quote."""

Note  that  the  indentation  inside  the  string  does  not  have  to  align  with  the  start  of  the

statement.  Any  whitespace  at  the  beginning  or  end  of  the  internal  lines,  i.e.  between  the

opening  and  closing  triple  quotes,  does  make  a  difference  though.  Hence,  if  the  second

line of text were indented, then those indentation spaces would be present in the string.

The  last  of  the  basic  data  types  we  cover  here  is  a  special  built-in  value  called  None,

which can be thought of as representing nothingness or that something is undefined. For

example,  it  can  be  used  to  indicate  that  a  variable  exists,  but  has  not  yet  been  set  to

anything specific. Example usage:

z = None


Finally, if you have a variable and want to know what its data type is then you can use

the type() function. This actually generates a special object representing the type, though it

prints out in an informative way:

print( type(x) ) # 'complex'

print( type(z) ) # 'NoneType'


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   29   30   31   32   33   34   35   36   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish