Python Programming for Biology: Bioinformatics and Beyond



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

Name

Description

Example

True


A Python object that represents

truth in Boolean logic.

foundPositive = False

for value in numbers:

if value > 0:

foundPositive = True

break

False


A Python object that represents

falsehood in Boolean logic.

[As above]

None


A Python object that represents an

absence, or that something is

undefined.

value = myDict.get(key)

if value is None:

print("key was not in

dictionary")

print("(or its value was

None)")

Note: the .get() method of Python

dictionaries gives None if a key is

absent.

Mathematical operations

The following table lists the standard mathematical operations that are inbuilt into Python.

Some  of  these  are  specified  with  operator  symbols,  while  others  use  standard  named

functions.



Operation

Description

Example

x + y


Addition: x plus y.

revenue = profit + expenses

x - y

Subtraction: x minus y:



income = profit - taxes

x * y


Multiplication: x times y.

area = volume * height

x / y

Division: x divided by y, within



the precision allowed by the

system. Note that in Python 2

dividing two integers gives an

mean = (x + y + z ) / 3.0




integer (it gives a floating point

number in Python 3).

x // y

Integer floor division: x divided



by y but giving the nearest

whole number rounded

downwards.

a = 13.0 // 5.0

The value of a is 2.0.

x % y


Modulus: find the remainder

when dividing x by y.

a = 13 % 5

The value of a is 3.

-x

Negate the value of x,



equivalent to multiplying by −1.

a = 5


b = -a * 3

The value of b is −15.

a + bj

Specifies a complex number a +



bi: (a is the real part; b is

imaginary). Here b must be an

explicit number, not a variable.

x = 1.0 + -1.0j

print(x * x)

Gives 0-2i (-2j in Python)

abs(x)

Gives the absolute value of x,



irrespective of sign, i.e. makes

values positive.

a = abs(-7)

The value of a is 7.

int(x)

Convert x into the integer



(whole number) equivalent;

gives an integer data type,

rounding towards 0 as required.

A second argument is the base in

which to interpret x.

int(‘ 21 ‘)

int(3.0 * 7.0)

int(‘10101’, 2)

All these values are 21.

long(x)


Convert x into a long integer

(i.e. of arbitrary length): this is

mostly redundant. Not available

in Python 3.

x =

long(12345123451234512345)



Note: int() will automatically

create long integers as needed.

float(x)

Convert x into the equivalent

floating point number: a fixed

precision number with

significant digits and an

exponent.

c = float(‘ 6.0322e23 ‘)

d = float(12)

round(x[,n])

Round x to the nearest whole

number or optionally accepts n,

stating how many decimal

a = 1.5555

b = round(a) # 2.0

c = round(a, 2) # 1.56



places to round to.

complex(a,b)

Creates an imaginary number

with real part a and imaginary

part b, i.e. a + bi.

c = complex(1, -2)

d = c.conjugate()

divmod(x, y)

Divide x by y giving the integer

floor and remainder as separate

values.

a, b = divmod(13.0, 5.0)

The value of a is 2.0 and b is

3.0.


pow(x, y)

or

x ** y



Raise x to the power of y, i.e. x

y

.



a = 2 ** 3

The value of a is 8.




Download 7,75 Mb.

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