function & positional / keyword arguments & global / local variables
MY_CONSTANT = 2 # variable globale en majuscule
# it can be aceesed and modified by all of function
# pas besoin de passer le aux fonctions
def function_name(X, Y): #X, Y postional arguments
Z = X * Y
A = X + Y # Z, A variable local
return Z, A # revoyer les résultats # equal to return [Z, A]
# return (Z, A) to create a tuple
x = 2
y = 1 # variable global # il faut passer aux fonctions
function_name(X = x, Y = y) # X, Y keyword arguments
# equal to function_name(x, y) #passage d'argument
class MyFunctions:
def function1(self):
...
def function2(self):
...
my_functions = MyFunctions()
my_functions.function1()
my_functions.function2()
# file My_module.py
def My_funtion():
...
print('Hello from my_module.py')
if __name__ == '__main__':
print('Hello from main method of my_module.py')
# run My_model.py
Hello from my_module.py
#print directly the message
# other file in which we import our module
import My_module.py as m
m.My_function()
#it don't print the message but functions in module can be accessed
#Python ne permet pas la modification d'une variable globale dans une fonction.
>>> def ma_fonction():
... x = x + 1
...
>>> x = 1
>>> ma_fonction()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in fct
UnboundLocalError: local variable 'x' referenced before assignment
soit déclarer la variable est globale
>>> def ma_fonction():
... global x
... x = x + 1
#Soyez extrêmement attentifs avec les types modifiables (tels que les listes)
#car vous pouvez les changer au sein d'une fonction :
>>> def ma_fonction():
... liste[1] = -127
...
>>> liste = [1,2,3]
>>> ma_fonction()
>>> liste
[1, -127, 3]
|
FASTA
|
protein sequence
|
|
GenBank
|
file format for storing DNA or protein sequences
|
|
PDB
|
protein structure
|
|
CSV, TSV
|
table
|
|
XTC ...
|
file for molecular dynamic
|
|
mol2
|
topology file
|
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.