Category:20th-century introductions
Category:Reagents for organic chemistry
Category:Chemical nomenclatureQ:
How do i pass a function as a parameter
I am trying to pass the string "hello" as a parameter to another function.
.Then i'm trying to return that value. I am also using python.
def main():
j = -1
for i in range(0,1):
print(i)
j = j + 1
print(j)
print('hello')
def my_fun(j):
return 'hello'
def main():
j = -1
for i in range(0,1):
print(i)
j = j + 1
print(j)
print('hello')
My problem here is that i want to return the 'hello' variable in my main function but am getting a syntax error as the'my_fun' function is not defined yet.
I have tried putting'my_fun()' before main() but then'my_fun' is not returning the value.
A:
Welcome to the world of Python!
In Python, functions are first class citizens, i.e., they can be passed around as arguments and returned as results. Thus, "hello" is a perfectly valid expression, so the first thing we need to do is import "hello" at the top of our file.
Then, we'll define our function and call it:
def my_fun(j):
return "hello"
main()
Run it and enjoy your lovely "hello"!
Molecular structure of the mouse CD4 glycoprotein complexed with two oligosaccharide chains.
The mammalian cell-surface glycoprotein CD4 is a member of the immunoglobulin superfamily and a crucial component of the T cell receptor. CD4 associates with specific membrane proteins, the most important of which are the proteins CD8, CD2, and the receptor for interleukin-2, the latter two of which are known to be359ba680
Related links:
Comentarios