Python Programming for Biology: Bioinformatics and Beyond


Not a regular printable symbol. 2



Download 7,75 Mb.
Pdf ko'rish
bet88/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   84   85   86   87   88   89   90   91   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

1

Not a regular printable symbol.



2

When the variable is garbage collected; its memory released.



3

http://www.ncbi.nlm.nih.gov/pubmed

.



7

Object orientation

Contents

Creating classes

Class definition

Class functions

Class and object attributes

Class constructors

Example: molecule, protein and amino acid classes

Further details

Class and object dictionary

String attribute access

Class information

Creating classes

For  simple  tasks  involving  short  programs,  you  can  survive  perfectly  well  with  the

standard  Python  data  types  for  holding  information,  such  as  lists  and  dictionaries.

However,  for  more  complicated  tasks  involving  long  programs,  this  often  becomes

unwieldy. There are various ways to deal with this issue, but one of the most fruitful is the

ability to define your own data types: objects built to your own specification, organised in

the way that is convenient to you. Modern computer languages do this via the introduction

of  bespoke  object  definitions  that  are  known  as  classes  and  this  kind  of  thinking  is

generally termed object-oriented programming.

When  creating  your  own  custom  data  types,  the  class  is  the  definition  of  a  particular

kind of object in terms of its component features and how it is constructed or implemented

in code. The term object, however, refers to a specific instance, or occurrence, of the thing

which has been made according to the class definition. The making of an object of a given

class  is  what  is  usually  termed  instantiation.  A  convenient  analogy  is  to  think  of  the

blueprint for a house being like a class, but the actual, solid house being the object. Also,

given a single blueprint one may build many instances of different house objects, all to the

same  design.  It  is  quite  common  to  use  the  words  ‘class’  and  ‘object’  interchangeably,

even  in  the  same  context,  although  they  mean  different  things,  and  it  is  important  to

understand  the  difference.  As  it  happens,  everything  that  is  brought  into  existence  in

Python is an object, so even integer and floating point numbers are objects, although most

of the time you can work without noticing that.



There are various definitions of what constitutes object-oriented programming, and here

the exact details do not matter much, since we are using what Python has provided in this

regard.  One  common  principle  seen  in  many  programming  languages  is  that  the  class

definition should make available certain useful functionality, and that internal information,

about  how  a  specific  class  is  implemented,  should  be  hidden  from  the  outside.  This  is

called information hiding and encapsulation. In this regard, however, Python does not take

a particularly strict view and you can prod and probe virtually every part of an object, if

you  know  how.  Nonetheless,  you  can  work  as  though  there  were  encapsulation,  and  we

will use this practically in the next chapter. As an example, suppose you have a Molecule

class  that  models  how  biological  molecules  are  constructed.  This  might  have  defined  a

function called getName(), which gives back the name of the molecule as a text string. For

the  person  who  is  using  this  function,  there  should  be  no  requirement  to  know  how  the

molecule’s  name  is  stored  internally  or  how  the  function  is  implemented,  just  that  the

function exists and provides the name of the molecule.




Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   84   85   86   87   88   89   90   91   ...   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