Python Programming for Biology: Bioinformatics and Beyond



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

Inbuilt functions

The  following  lightly  describes  selected,  standard  Python  functions  which  require  no

imports to use. See the standard Python documentation for more technical descriptions and

details of all arguments. Optional arguments are specified in italics.



Function

Description

Example

abs(val)


Generates the absolute value

of a number, i.e. its

magnitude, irrespective of

sign.


numbers = [-3,-2,-1,0,1,2,3]

print([abs(x) for x in

numbers])

Result is [3, 2, 1, 0, 1, 2, 3].

all(vals)

Determines whether all the

items in a collection (or other

iterable) have true values.

all([True, False, True]) #

False


all([1,2,3,4]) # True


Gives True if they do and

False otherwise. This does

not work on multi-

dimensional NumPy arrays.

any(vals)

Determines whether any of

the items in a collection (or

other iterable object) have

true values. Gives True if so

and False otherwise. This

does not work on multi-

dimensional NumPy arrays.

any([True, False, True]) #

True


any([False, None, 0.0]) #

False


bin(val)

Creates a string representing

the binary version of a

number; 0 and 1 characters

prefixed with ‘0b’. Available

from Python 2.6 onwards.

x = 341

print(bin(x))

Result is ‘0b101010101’.

bool(val)

Determines whether a value

is logically true or false, i.e.

converts a value into a

Boolean object.

bool(0.0) # False

bool(3.0) # True

bool(‘abc’) # True

callable(obj)

Determines whether an object

is callable, i.e. can be

invoked like a function.

Giving True if so and False

otherwise.

y = 1.47


x = abs # The inbuilt

function


print(callable(y),

callable(x)) # False, True

chr(code)

Gives the ASCII character

string for an integer code

number. Performs the inverse

operation to ord().

i = ord(‘A’)

print(chr(i+1))

Result is ‘B’.

cmp(val1, val2)

Compares two objects and

gives back 1 if the first is

larger, −1 if the second is

larger or 0 if they are equal.

Not available in Python 3.

cmp(1,2) # -1

cmp(2,2) # 0

cmp(2,1) # 1

complex(real,

imag)

Creates a complex number



using separate real and

imaginary components.

x = complex(1,-1.4142)

Result is (1-1.4142j); 1-

1.4142i.



dict(vals)

Creates a dictionary from a

specified object, e.g. to copy

another dictionary or to

convert a list of

keyword:value pairs.

x = [(1,1),(2,4),(3,9),(4,16)]

y = dict(x)

Result is {1:1, 2:4, 3:9,

4:16}.


dir(obj)

Gives a list of variable names

that are present within the

current program scope, or if

object is specified the names

associated with that object as

attributes.

print(dir())

print(dir(”))

First line shows imports and

declarations. Second line

shows attributes of string

types.

divmod(val1,



val2)

Divide x by y giving the

integer floor and remainder

as separate values.

[See Mathematics section]

enumerate(vals,



start)

Generates sequential pairs of

(number, item) from a

collection or other iterable

object, e.g. extracting objects

and their indices from a list.

Creates an iterator object.

Takes a start number as a

second argument.

letters = ‘GCAT’

enum =

list(enumerate(letters))



Result is [(0,‘G’), (1,‘C’),

(2,‘A’), (3,‘T’)].

eval(exprn, locals,

globals)

Evaluates a string as an

expression in Python syntax,

i.e. to allow the dynamic

generation of expressions.

Allows optional dictionary

arguments to specify global

and local scope variable

names.

text = ‘x*7+5*y’



x = 4.7

y = 8.1


eval(text)

Result is 73.4.

execfile(fileName,


Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   449   450   451   452   453   454   455   456   ...   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