Python Programming for Biology: Bioinformatics and Beyond


Note: above lines are for Python 2. print(‘Hello’) Note



Download 7,75 Mb.
Pdf ko'rish
bet448/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   444   445   446   447   448   449   450   451   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Note: above lines are for

Python 2.

print(‘Hello’)

Note: above line is for Python

2 or 3.


print(‘Data line’, file=fileObj)

Note: above line is for Python

3.

raise



Manually triggers an error

exception. May be used on its own

for custom exceptions or to re-

throw error objects caught with try:

and except:.

if x == 0.0:

raise

Exception("Detected zero")




return

Exits from a named function and

optionally passes back one or more

items to the point where the

function was called.

def countWords(text):

n = len(text.split())

return n


print(countWords('Hello

world'))


try

Encapsulates a block of code so that

if an illegal state triggers an

exception the error can be caught

and dealt with in a special way.

Used in conjunction with except

and or finally keywords.

try:


x += a / b

except ZeroDivisionError:

print("Ignored zero

division")

while

Continues the repeated, iterative



execution of a block of code while

a certain condition holds.

x = 2

while x < 1000:



print(x)

x *= 2


with

Encapsulates a block of code using

a context manager object, which

has dedicated methods to deal with

starting and cleanly ending the

context. Generally used so that the

context can have clean-up before it

exits or an exception occurs.

Optionally uses the as keyword.

with open(fileName) as

fileObj:

for line in fileObj:

print(line)

The with statement

encapsulates the file reading

block so the file is closed at

the end or if an error occurs.

yield


Used inside a function to pass back

a value like return, but allows the

function to be re-entered, keeping

the previous state. Used to make

generator functions.

def generateSquare():

for x in range(1,10):

yield x*x

print(generateSquare())

# 1


print(generateSquare())

# 4



Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   444   445   446   447   448   449   450   451   ...   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