Python Programming for Biology: Bioinformatics and Beyond


This would allow you to calculate the angle between two directions, for example. See Chapter 9 . 2



Download 7,75 Mb.
Pdf ko'rish
bet60/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   56   57   58   59   60   61   62   63   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

1

This would allow you to calculate the angle between two directions, for example. See

Chapter 9

.

2

Those not encapsulated in an abstract definition.



5

Functions

Contents

Function basics

Function definitions and calls

Return values

Input arguments

Optional arguments

Example: reverse transcribe a DNA sequence

Anonymous arguments

Variable scope

Module and function variables

Global variables

Further considerations

Nesting functions

Lambda: anonymous functions

Decorators

Function basics

Functions are the mainstay of most programming in Python. The point of a function is to

group a specific set of operations in a specific, hopefully not too large, piece of code. A

function in Python is what is sometimes referred to in other languages as a subroutine. A

function  is  written  as  a  block  of  code  that  is  separate  from  the  main  program  flow,  but

which can be called upon to operate in many separate places. Once defined, a function will

not do anything in particular until instructed to act, often with a specific set of data. Many

functions  perform  jobs  that  are  general  and  can  be  used  in  more  than  one  situation.  The

benefits from using functions in your programs are clear: they reduce the amount of code

you have to write and maintain; they allow you to use existing code that is already tested;

they improve the clarity of your code by separating mundane tasks from more important

ones, and they allow you to recombine code in different ways to perform new tasks.

Below is a very simple example of a function being used: the function name is abs and

it  is  used  to  find  the  absolute  magnitude  of  a  number,  the  positive  value  removing  any

minus sign. In this case we have used an inbuilt Python function but it is also possible to

define new functions and import existing ones from other files.




x = abs(-3.0)

print(x) # Result: 3.0

When  discussing  functions  we  will  address  two  distinct  issues.  The  first  concerns  the

definition of the function; this is to state what operations it performs. The second concerns

how the function is used within a working program; this is to say how a function is called,

to do something in a given situation.




Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   56   57   58   59   60   61   62   63   ...   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