Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet68/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   64   65   66   67   68   69   70   71   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Global variables

If a variable is defined at a module level and if it is desired to change it inside a function,

then Python requires a ‘global’ statement in the function to get hold of the variable from

outside.  For  example,  suppose  we  have  a  counter  that  is  incremented  inside  a  function,

then we could do

counter = 0

def someFunction(argument):

global counter

counter += 1

performOperation(argument)

In  some  ways  it  is  good  that  Python  has  this  arduous  way  of  modifying  variables

defined  at  module  level,  because  it  is  generally  not  a  good  idea  to  code  this  way.  Often

you would avoid using global entirely by passing variables in as arguments and collecting

them as output:

counter = 0

def someFunction(argument, counterVal):

counterVal += 1

performOperation(argument)

return counterVal

counter = someFunction(input, counter)




Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   64   65   66   67   68   69   70   71   ...   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